Jump to content

**new: Connecting To Mysql Db From Php**


chibineku
 Share

Recommended Posts

Thought I'd reuse this thread - why not? The first issue was resolved.I have copied this from the tutorials pages:

<?php$con = mysql_connect("localhost","root","*****");if (!$con)  {  die('Could not connect: ' . mysql_error());  }// Create databaseif (mysql_query("CREATE DATABASE my_db",$con))  {  echo "Database created";  }else  {  echo "Error creating database: " . mysql_error();  }// Create tablemysql_select_db("my_db", $con);$sql = "CREATE TABLE Persons(FirstName varchar(15),LastName varchar(15),Age int)";// Execute querymysql_query($sql,$con);mysql_close($con);?>

And I get this error message:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)I have been all over the shop trying to find the reason for it. I had the mysql installation through port 3307 because the first installation failed but left most of the files behind, but I've sinced changed it to 3306. It works, I can do everything at the command line, but I can't seem to get any info on this problem that is in english - the level of techno-babble I am finding on other fora regarding this problem is staggering. I don't know anything about sock(et)s, but I'm willing to learn if it's put in words I can understand! Any thoughts would be greatly appreciated. Thanks!!

Edited by chibineku
Link to comment
Share on other sites

I found a site that told me to enter:"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld" --consoleWhich produced an error:InnoDB: Operating system error number 5 in a file operation. I've also tried changing directory to c:\program files\mysql\mysql server 5.1\bin and typing all the shell> mysql stuff.I have tried entering the set username and password, and it still says access denied. More: I ran the config instance .exe and found that I hadn't checked a box that makes the service available from the command line. However, I ran into a problem that I was getting yesterday when I installed MySQL: The last screen of the installation shows you the status, and it fails to start the service. I am not sure what that is about either.

Link to comment
Share on other sites

OK, well, the service needs to be started before you can connect to the server. You'll need to find out why it's not starting. You might be able to check the event viewer in Windows for error messages, or it might also create its own error log file.Also, you're not actually typing "shell>", right?Check here too:http://forums.mysql.com/read.php?21,119097,119097#msg-119097

Link to comment
Share on other sites

See first post - thread topic has changed!!

Edited by chibineku
Link to comment
Share on other sites

**bump**

Link to comment
Share on other sites

A socket is similar to a port. When you open your browser and connect to google.com, you're connecting on port 80, which is the HTTP port. MySQL listens on its ports also. A socket is basically a manual connection to a specific port, once the socket is open you have a connection between two machines on a certain port. The Internet Protocol (the IP in TCP/IP) connects using sockets.http://en.wikipedia.org/wiki/Internet_socketIf you're using MySQL 5, you might need to use a different way to connect. I'm ripping this off from a Linux server, so I'm not sure if it's going to be the same thing, but try this instead of localhost:localhost:/tmp/mysql5.sock

Link to comment
Share on other sites

Hm, I had found similar ideas on unix/linux fora too, and it generates the same error (I tried it again this time anyway, just to be sure). Apparently it's a fairly common problem, but from looking at the mysql.com forum, it's clearly not a known bug (a mod from sun/mysql said so). I thought it would be fairly simple to alter some config file to point to a different/the correct socket. It might be worth trawling a few MS fora instead, or joining one and asking there. I get the feeling that, as with most things Windows, it's frowned upon and not very well supported in the open source community, so nobody has fixes at hand. I appreciate your continued interest and suggestions, and if you have any more I will be happy to try them.

Link to comment
Share on other sites

Another linux fix is to swap the hostname with ip 127.0.0.1, which i tried, and now get this error:Lost connection to MySQL server at 'reading initial communication packet', system error: 111This feels like progress, albeit not as much as I was hoping for. I will research more later, but just thought I'd throw it out there in case it meant anything to anyone.

Link to comment
Share on other sites

It's odd that you're having problems, everything worked for me the first time I installed it. You might just want to reinstall, make sure to get everything off after uninstalling. You might be able to find a manual uninstall procedure to use a checklist.

Link to comment
Share on other sites

I had a eureka moment in the shower today, and I'm too embarassed to even start listing the silly (nay, idiotic) mistakes I was making. Suffice to say it is working now - many thanks for your efforts, though!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...