Good evening
I teach Computing Science in secondary school and I'm trying to create a series of practical tasks for senior pupils. They have already created a MySQL database using EasyPHP and used this successfully to create a database-driven website (due to restrictions on the school network, the pupils run EasyPHP from USB pen drives). I now want them to access the same database from a Livecode program.
I am working with databases and Livecode for the first time and I've encountered problems trying to connect to the database using the following code:
put "localhost" into databaseAddress
put "testDB" into databaseName
put "root" into databaseUser
put "root" into databasePassword
put revOpenDatabase("MySQL", databaseAddress, databaseName, databaseUser, databasePassword) into connect
if connect is a number then
put connect into linkID
answer info "Connected to the database." & cr & "Connection ID = " & linkID
else
put empty into linkID
answer error "Unable to connect to the database:" & cr & connect
end if
This generates the error "Can't connect to MySQL server on localhost(0)". I suspect the issue is that I've not used the full path name of the database but I'm not sure what that is.
I found an earlier post with a similar problem 'MySQL + Localhost using MAMP'. The solution makes use of all 6 parameters associated with the revOpenDatabase function
get revOpenDatabase("mysql", "localhost", "testdb", "root", "root",false,"/Applications/MAMP/tmp/mysql/mysql.sock"
The school PCs run Windows 7 so I'm guessing that the pathname would be something like: "E:/EasyPHP/EasyPHP-DevServer-14.1VC9/binaries/mysql/data/testdb"
However, when I try using this pathname, I still generate the same error message as before.
Any help would be very much appreciated. Many thanks in anticipation.
MySQL with EasyPHP
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: MySQL with EasyPHP
Hi,
not sure if I can help, but I may be able to give some hints:
1.) The second parameter in revOpenDatabase("mysql", ...) is the URL ("mySite.com"). If "localhost" doesn't work you might try the equivalent "127.0.0.1". Maybe add a port: "127.0.0.1:3306"
If this doesn't work, try the real IP of the machine (or the real URL).
2.) When using paths on windows and having problems, always additionally try the backslash variant: "C:\aFolder\aFile.txt" instead of "C:/aFolder/aFile.txt" ...
I don't have a local MySQL here, but when connecting to a local SQLite I use this variant.
But as far as I see in the doku there's no need for a path anyways.
3.) Make sure MySQL allows connections other but from PhP! This is often disabled for security reasons.
Hope this helps! Have fun!
not sure if I can help, but I may be able to give some hints:
1.) The second parameter in revOpenDatabase("mysql", ...) is the URL ("mySite.com"). If "localhost" doesn't work you might try the equivalent "127.0.0.1". Maybe add a port: "127.0.0.1:3306"
If this doesn't work, try the real IP of the machine (or the real URL).
2.) When using paths on windows and having problems, always additionally try the backslash variant: "C:\aFolder\aFile.txt" instead of "C:/aFolder/aFile.txt" ...
I don't have a local MySQL here, but when connecting to a local SQLite I use this variant.
But as far as I see in the doku there's no need for a path anyways.
3.) Make sure MySQL allows connections other but from PhP! This is often disabled for security reasons.
Hope this helps! Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
-
- Posts: 2
- Joined: Wed Mar 11, 2015 11:31 pm
Re: MySQL with EasyPHP
Many thanks for your prompt reply.
Replacing 'localhost' with '127.0.0.1' is indeed the solution. I only wish I had thought of that myself - seems so obvious now!
Replacing 'localhost' with '127.0.0.1' is indeed the solution. I only wish I had thought of that myself - seems so obvious now!