MySQL + Localhost using MAMP

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
grandlorie
Posts: 7
Joined: Tue May 28, 2013 1:48 pm

MySQL + Localhost using MAMP

Post by grandlorie » Tue May 28, 2013 1:57 pm

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
-----------------------------------------------------------

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: MySQL + Localhost using MAMP

Post by Klaus » Tue May 28, 2013 3:00 pm

Hi,

try this:
...
put revOpenDatabase("mysql", tDatabaseAddress, ....
## "mysql" -> lower case!
## I think Livecode is picky in this respect.
...

Best

Klaus

grandlorie
Posts: 7
Joined: Tue May 28, 2013 1:48 pm

Re: MySQL + Localhost using MAMP

Post by grandlorie » Tue May 28, 2013 3:40 pm

Klaus

Thanks for your reply,
but unfortunately it is the same error

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am

Re: MySQL + Localhost using MAMP

Post by icouto » Wed May 29, 2013 2:03 am

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!

grandlorie
Posts: 7
Joined: Tue May 28, 2013 1:48 pm

Re: MySQL + Localhost using MAMP

Post by grandlorie » Wed May 29, 2013 10:08 am

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

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am

Re: MySQL + Localhost using MAMP

Post by icouto » Thu May 30, 2013 2:10 am

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.

William Jamieson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 212
Joined: Fri Feb 01, 2013 1:31 am
Contact:

Re: MySQL + Localhost using MAMP

Post by William Jamieson » Thu Jul 18, 2013 12:41 pm

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?

Post Reply