I've installed Apache2 and PHP5 on my computer and they run fine, and I've installed MySQL and it works. But when I try and connect to the mysql database from PHP, I get this error:
Warning: mysql_connect() [function.mysql-connect]: Can't create TCP/IP socket (10106)
Anyone know what I might be doing wrong here?
Thanks
PHP wont connec to MySQL
Started by Pax, Mar 20 2006 04:21 PM
4 replies to this topic
#1
Posted 20 March 2006 - 04:21 PM
#2
Posted 20 March 2006 - 06:51 PM
Can you post your code?
Hoot
Hoot
#3
Posted 20 March 2006 - 07:34 PM
I'm not at my computer right now, so I don't have the exact code, but its somthing like this:
There's more too it than that. Error checking and blah blah. But thas the gist of it. Point is, this works fine when I upload it, but when I run it on my localhost, I can't connect to the db. I can connect to the mysql db via the command promt, so I know it works. And the PHP + Apache works as well. Just not together. My problem is somewhere in the config files, I'm just not sure *where* in the config files.
$db_host = "localhost"; $db_user = "root"; $db_pw = "pass"; $db_name = "mydb"; $connect = mysql_connect($db_host, $db_root, $db_pw); mysql_close($connect);
There's more too it than that. Error checking and blah blah. But thas the gist of it. Point is, this works fine when I upload it, but when I run it on my localhost, I can't connect to the db. I can connect to the mysql db via the command promt, so I know it works. And the PHP + Apache works as well. Just not together. My problem is somewhere in the config files, I'm just not sure *where* in the config files.
#4
Posted 20 March 2006 - 08:58 PM
Pax, on Mar 20 2006, 07:34 PM, said:
I'm not at my computer right now, so I don't have the exact code, but its somthing like this:
There's more too it than that. Error checking and blah blah. But thas the gist of it. Point is, this works fine when I upload it, but when I run it on my localhost, I can't connect to the db. I can connect to the mysql db via the command promt, so I know it works. And the PHP + Apache works as well. Just not together. My problem is somewhere in the config files, I'm just not sure *where* in the config files.
$db_host = "localhost"; $db_user = "root"; $db_pw = "pass"; $db_name = "mydb"; $connect = mysql_connect($db_host, $db_root, $db_pw); mysql_close($connect);
There's more too it than that. Error checking and blah blah. But thas the gist of it. Point is, this works fine when I upload it, but when I run it on my localhost, I can't connect to the db. I can connect to the mysql db via the command promt, so I know it works. And the PHP + Apache works as well. Just not together. My problem is somewhere in the config files, I'm just not sure *where* in the config files.
You need to provide your database name. Try this code:
$db_host = "localhost"; $db_user = "root"; $db_pw = "pass"; $db_name = "mydb"; mysql_connect($db_host,$db_user,$db_pw); mysql_select_db($db_name);
That should work. Works for me. Let me know if it still gives you an error. Thanks.
-Perry
#5
Posted 20 March 2006 - 09:54 PM
Yah it does...the problem *isnt* my coding. It works fine when uploaded to an actual server. I'm trying to setup PHP and MySQL to run on my computer, so I don't need to rely on the internet to do my work. Problem is, the PHP wont make the connection to the MySQL db running on my machine.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
