Getting PHP to talk with mySQL

software development

#1

Hello list,
I’m teaching myself basic PHP to mySQL programming and seem to be hung up or something. I keep getting an unable to connect message and feel I have the initial connection path to my mySQL account at Dreamhost wrong. This is the code I’m using (it’s a webmonkey tutorial) followed by the error message(s) I’m getting. Obviously, the real code has my real login and password but I’ve left those areas generic for my privacy. I do have that info in the code on the server. ‘testingphp.kselected.com’ is the hostname i’ve set up for the db. Any help would be greatly appreciated. Thanks in advance.

<?php

mysql_connect (testingphp.kselected.com, mylogin, mypassword);

mysql_select_db (testingPHP);

mysql_query (“INSERT INTO submitForm1 (firstName, lastName)
VALUES (’$firstName’, ‘$lastName’)
”);

print ($firstName);

print (" ");

print ($lastName);

print ("

");

print (“Thanks for submitting your name.”);

?>

and i get back.

Warning: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 5

Warning: MySQL Connection Failed: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 5
Warning: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 7

Warning: MySQL Connection Failed: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 7

Warning: MySQL: A link to the server could not be established in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 7

Warning: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 11

Warning: MySQL Connection Failed: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 11

Warning: MySQL: A link to the server could not be established in /home/.abbey/tr394/kselected.com/ITP/Grow/Captions/submitform.php on line 11

Tim


#2

Hello!

Do these lines:

mysql_connect (testingphp.kselected.com, mylogin, mypassword);
mysql_select_db (testingPHP);

…look a lot like the ones in your actual script?

The arguments for these are actually strings, so they should be quoted, ie.:

mysql_connect(‘testingphp.kselected.com’, ‘mylogin’, ‘mypassword’);
mysql_select_db(‘testingPHP’);

The best resource for PHP is the documentation on the PHP web site. It’s pretty well written, and contains a lot of annotated notes by PHP coders. The pages for the above two functions can be found here:

http://www.php.net/manual/en/function.mysql-connect.php
http://www.php.net/manual/en/function.mysql-select-db.php

Good luck!

  • Jeff @ DreamHost
  • DH Discussion Forum Admin

#3

Thanks Jeff,
Yeah I got it about two hours after I posted. It’s always something stupid like that which I completely overlook.

Greatly appreciated,
Tim


#4

[quote]Yeah I got it about two hours after I posted. It’s always
something stupid like that which I completely overlook.

[/quote]

No worries. If I had a dime every time I made some silly mistake programming, I’d have … A lot of dimes.

:>

  • Jeff @ DreamHost
  • DH Discussion Forum Admin