Page 1 of 1
MySQL + Localhost using MAMP
Posted: Tue May 28, 2013 1:57 pm
by grandlorie
Hi
I am having some trouble connecting to any database i have on my local server, i am using MAMP on my MAC and i can access all the databases (including the test one) through Joomla and vBulletin. but when i try to connect with Livecode i got the following error:
------------------
unable to connect to the database:
Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (2)
----------------
here is my Code ( i used 127.0.0.1 instead and same thing does not work)
------------------------------------------------------------
on mouseUp
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "localhost" into tDatabaseAddress
put "version2" into tDatabaseName
put "version2" into tDatabaseUser
put "version2" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
-- check if it worked and display an error message if it didn't
-- & set the connection ID global
if tResult is a number then
put tResult into gConnectionID
answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end mouseUp
-----------------------------------------------------------
Re: MySQL + Localhost using MAMP
Posted: Tue May 28, 2013 3:00 pm
by Klaus
Hi,
try this:
...
put revOpenDatabase("mysql", tDatabaseAddress, ....
## "mysql" -> lower case!
## I think Livecode is picky in this respect.
...
Best
Klaus
Re: MySQL + Localhost using MAMP
Posted: Tue May 28, 2013 3:40 pm
by grandlorie
Klaus
Thanks for your reply,
but unfortunately it is the same error
Re: MySQL + Localhost using MAMP
Posted: Wed May 29, 2013 2:03 am
by icouto
LiveCode assumes that you have a standard installation of MySQL in your system, so it is trying to connect to MySQL using the usual socket location. MAMP, however, places its MySQL socket in a different location:
"/Applications/MAMP/tmp/mysql/mysql.sock". Therefore, you need to tell the revOpenDatabase command where your MAMP MySQL socket can be found, like this:
Code: Select all
revOpenDatabase("mysql", "localhost", tDBName, tUserName, tPassword,false,"/Applications/MAMP/tmp/mysql/mysql.sock")
Here is a complete test script, that works in my system, using MAMP - put it in a button and try it out yourself:
Code: Select all
on mouseUp
local tDatabaseId
get revOpenDatabase("mysql", "localhost", "testdb", "root", "root",false,"/Applications/MAMP/tmp/mysql/mysql.sock")
if it is not an integer then
answer it with "OK" as sheet
else
put it into tDatabaseId
answer "Database Connection Established. Database ID: " & tDatabaseId with "OK" as sheet
revCloseDatabase tDatabaseId
end if
end mouseUp
I hope this helps!
Re: MySQL + Localhost using MAMP
Posted: Wed May 29, 2013 10:08 am
by grandlorie
Hi icouto
Thanks a lot that helps, and now it is working
and for those who wanna follow the code i posted above the final code is:
--------------------------
on mouseUp
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "localhost" into tDatabaseAddress
put "version2" into tDatabaseName
put "version2" into tDatabaseUser
put "version2" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword,false,"/Applications/MAMP/tmp/mysql/mysql.sock") into tResult
-- check if it worked and display an error message if it didn't
-- & set the connection ID global
if tResult is a number then
put tResult into gConnectionID
answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end mouseUp
--------------------------
Just one more thing to follow:
I was struggling also connecting Livecode to a database on goDaddy server, regarding the database address is it the same as the host name? or it is just mysite name link
can you please post a code example ..
Thanks once again for your help
Re: MySQL + Localhost using MAMP
Posted: Thu May 30, 2013 2:10 am
by icouto
I don't know if I can help you here:
grandlorie wrote:
I was struggling also connecting Livecode to a database on goDaddy server, regarding the database address is it the same as the host name? or it is just mysite name link
can you please post a code example ..
I thought goDaddy was just a domain name registrar, but it seems I'm wrong!
The answer to your question will depend on what kind of account/setup you have with goDaddy.
If you have a shared host account, with a MySQL database included, the MySQL database will not be open to direct public access by everyone - this would be a huge security risk, that would put everyone's database at risk. In shared host situations, the ISP usually only allows you to 'connect' to your MySQL database from a local script - that is, a script running on the same server as the database. In this kind of setup, you will usually have a script on the server - ie., a PHP script, or a
LiveCode Server script - that receives incoming data requests via HTTP, queries the database, and then sends the data back to the client. Andre Garzia, a well-known LiveCode developer, has a web framework written in LiveCode, called
RevSpark, which allows you to write server-side web apps quite easily. If you're going to be going down that route, I'd have a look at that.
It is also possible, in most shared hosting setups, to allow a
specific IP address to access your shared database from outside. To do that, you usually have to go to your Admin Panel - ie., usually cPanel - and somewhere in the 'Database' section of the Admin enter the IP Address that is going to be accessing the database.
I hope this helps.
Re: MySQL + Localhost using MAMP
Posted: Thu Jul 18, 2013 12:41 pm
by William Jamieson
Hello icouto,
What would be the main differences between using Livecode as it is and using the RevSpark program? I looked at how it is formatted and it looks like relatively similar functions. Although I don't quite know what he streamlined from the original code. Can you give any insights?