Hi, MySQL works just fine. I guess it is rather a syntax problem. With MySQL you have to be very careful with commas and quotes etc. when composing the MySQL argument. Are you working with a test database on a server or with a local database on your computer? I suggest to start with a local database, the advantage is that you can check the actual content of that database in any text editor. A local database is opened like that (modify the filepath to your database):
Code: Select all
## Connect to the database
## Save the connection id
put specialFolderPath("desktop") & "/Beginners Course/Week 5/Sample Stacks/emailaddresses.sqlite" into tDatabasePath
put revOpenDatabase("sqlite",tDatabasePath,,,,) into sDatabaseID
I assume that you have a database with a table and a column. Now, when adding content to your table you have to construct the MySQL argument very carefully. I post here some sample code that has worked for me:
Code: Select all
on mouseUp
global connectID
local gameinfo, tSQL
put empty into gameinfo
put empty into tSQL
-- check if database is connected
if connectID is "" then
answer information "No Database is Connected!"
exit mouseUp
end if
-- Collect game data
put "'" & field "name" & "','" & field "date" & "','" & field "time" & "','" & field "city" & "','" & field "country" & "','" & field "location" & "','" & field "address" & "','" & field "context" & "','" & field "info" & "'" into gameinfo
-- clean input data
-- Construct SQL
put "INSERT INTO games(gamename,date,time,city,country,location,address,context,info) VALUES(" & gameinfo & ")" into tSQL
-- Execute SQL
revExecuteSQL connectID,tSQL
put the result into tTmp
-- check for error
handleRevDBerror tTmp
if the result is not empty then
answer warning the result
exit mouseUp
end if
end mouseUp
Check how the variable
gameinfo is constructed. It is important to get it right with the single and double quotes. As an example, the variable
tSQL looks like this, before revExecuteSQL is executed:
Code: Select all
INSERT INTO games(gamename,date,time,city,country,location,address,context,info) VALUES('Goat Simulator','23.10.2012','17:00-19:00','Rijeka','Croatia','Molekula','Titosquare 1','Festival (annual)','live like a goat')
In your case the tSQL should probably look like this:
Code: Select all
INSERT INTO chat(chat field) VALUES('chatcontent')
When you have constructed your tSQL variable correctly do the MySQL execution like this:
Code: Select all
revExecuteSQL gConnectionID, tSQL
Another problem could be if the text that you want to store in your database contains quotes or tabs or returns, this messes up your MySQL argument. In such cases you have to replace those special characters in your text with something like this *TAB*.You would do it in my sample code where it is written "clean input data". Look for example here:
http://forums.livecode.com/viewtopic.php?f=8&t=21920
Good luck!
Best
Oliver