help connecting mySQL database to website using PHP?

  • Thread starter Thread starter Yiaggi
  • Start date Start date
Y

Yiaggi

Guest
Hi guys,

I am a web designer - fairly new to the whole mySQL / PHP area.

I have been studying mySQL for quite a while now and have quite a good understanding of it by following tutorials and reading a lot!

I have now got to the stage where I want to add a small pretend database to my website. I am not sure if I missed something along the way but I am finding this fairly tricky and a wondering if u web geniuses can help!?

Basically:

*I have a database 'phpdb' on my computer with one simple table in it.

*The tutorial I am following told me to enter this PHP code into my HTML code to 'call' the website and get a simple query result:

<?php
mysql_connect ("localhost", "myusername", "mypassword");
mysql_select_db (phpdb");
$result = mysql_query ("select * from usertable");
$numrows = mysql_num_rows ($result);
print "There are $numrows people in usertable\n";
?>

That all seems fairly straight forward i'm sure but I am constantly getting a error message that says:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www/sm22628/public_html/message_board.php on line 86

Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www/sm22628/public_html/message_board.php on line 87

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /var/www/sm22628/public_html/message_board.php on line 87

Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /var/www/sm22628/public_html/message_board.php on line 88

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/sm22628/public_html/message_board.php on line 88

---------------------------

Line 88 is the code that has my username & password. This is confusing me slightly .........

Am I meant to set this password in mysql to use here? My tutorial didnt instruct me to do so but it seems logical to me.

I only have a password for mysql ... it asks me for it when I log on - Is it that one?

If you could help that would be amazing! I thought I was starting to get somewhere after alot of reading but this has become a stumbling block!

Kind regards :)
 
Back
Top