Newbie - MYSQL Connection Problems

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
xclntdesign
Posts: 34
Joined: Sun Feb 06, 2011 8:33 pm

Newbie - MYSQL Connection Problems

Post by xclntdesign » Sun Feb 06, 2011 8:44 pm

I'm scratching my head on this one, and its probably because I don't know LiveCode well enough to figure it out for myself. It'll be one of those "duh" things.

Anyways, I have copied and slightly modified code from the "Exploring Revolution: Work with Databases" tutorial to connect to a MySQL database, and I'm not having much success.

Code: Select all

local sDatabaseId

on preOpenStack
   databaseConnect
  -- Show the first available record:
  goNext 0
  if the result is not empty then
    uiReset
end if
end preOpenStack

on databaseConnect
   get revOpenDatabase("mysql", "(RunRev website)", "test", "example", "example")
   
   if it is not an integer then
      error "Could not connect to database:" && it
      end if
  
      put it into sDatabaseId
      
      end databaseConnect
This code produces an error Handler: can't find handler near "error", char 1. So I've tried replacing the RunRev database information with my localhost info (running WAMP), and I get past that error, but now I get Handler: can't find handler near "goNext", char 1.

If I understand it correctly, goNext will go to the next record. But since I have not defined which table to look in, how does it know where to look for the next record, or am I looking at the problem all wrong?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Newbie - MYSQL Connection Problems

Post by bangkok » Mon Feb 07, 2011 6:18 am

First rule : test it by keeping it simple.

So no need of preopenstack handler, sub handler etc.

And by the way, "error" is not a command. Use instead "answer warning".

Create one button.
And put inside :

Code: Select all

on mouseup
 put revOpenDatabase("mysql", "(RunRev website)", "test", "example", "example") into dbID
   if dbID is not an integer then
      answer warning "Could not connect to database:" &dbID 
else
answer info "You are connected"
end if

put "SELECT * from yourtable" into dbSQL
   put revDataFromQuery(,,dbID,dbSQL) into myData
answer myData

 revCloseDatabase dbID
end mouseup
Voila. A basic handler. Opens the connection, sends the query, reads the result and closes the connection.

Post Reply