MySQL + Localhost using MAMP
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 7
- Joined: Tue May 28, 2013 1:48 pm
MySQL + Localhost using MAMP
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
-----------------------------------------------------------
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
Hi,
try this:
...
put revOpenDatabase("mysql", tDatabaseAddress, ....
## "mysql" -> lower case!
## I think Livecode is picky in this respect.
...
Best
Klaus
try this:
...
put revOpenDatabase("mysql", tDatabaseAddress, ....
## "mysql" -> lower case!
## I think Livecode is picky in this respect.
...
Best
Klaus
-
- Posts: 7
- Joined: Tue May 28, 2013 1:48 pm
Re: MySQL + Localhost using MAMP
Klaus
Thanks for your reply,
but unfortunately it is the same error
Thanks for your reply,
but unfortunately it is the same error
Re: MySQL + Localhost using MAMP
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:
Here is a complete test script, that works in my system, using MAMP - put it in a button and try it out yourself:
I hope this helps!
Code: Select all
revOpenDatabase("mysql", "localhost", tDBName, tUserName, tPassword,false,"/Applications/MAMP/tmp/mysql/mysql.sock")
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
-
- Posts: 7
- Joined: Tue May 28, 2013 1:48 pm
Re: MySQL + Localhost using MAMP
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
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
I don't know if I can help you here:
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.
I thought goDaddy was just a domain name registrar, but it seems I'm wrong!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 ..
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.
-
- VIP Livecode Opensource Backer
- Posts: 212
- Joined: Fri Feb 01, 2013 1:31 am
- Contact:
Re: MySQL + Localhost using MAMP
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?
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?