Jump to content


PHP wont connec to MySQL


4 replies to this topic

#1 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 20 March 2006 - 04:21 PM

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

#2 Hoot

    * Hooty Tooty Fruit *

  • Members
  • PipPipPipPip
  • 1,346 posts
  • Gender:Male
  • Location:Canada
  • Interests:Making Websites, Working in 3D, Playing the Drums

Posted 20 March 2006 - 06:51 PM

Can you post your code?

Hoot

#3 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

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:

$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 Perry

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 20 March 2006 - 08:58 PM

View PostPax, 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:

$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 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

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