Jump to content


Photo

php & mysql integration


  • Please log in to reply
5 replies to this topic

#1 ember

ember
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 April 2006 - 03:00 AM

Every time I try to set up a web server on my windows computer I get to this step and then flounder.

I've installed php and it's working grandly with apache.
I've installed and set up mysql, and reset the root pw and whatnot.
Both the apache2 and mysql services are running.
The "php_mysql.dll" line in php.ini is uncommented
The extensions line in php.ini is set correctly to c:\php\ext
Both c:\php and the mysql directory are in the PATH variable

yet when I try to connect to mysql from php I get "Can't connect to MySQL server on 'localhost'" (I got that from a failed IPB setup error message)

also when i view phpinfo, I have a section for mysql in the modules section. php's correctly identified my mysql client api version, but I suspect that's libmysql.dll talking and not mysql.exe

Have I missed a step here? The last time I had this problem I remember it being resolved by downloading some old mysql dll and pasting it all through the php dirs and the windows directories. But I'm using the 2nd-to-newest version of apache2, the 2nd-to-newest version of mysql, and a tested copy of ipb2. I fail to understand what's wrong, my configuration fits the instructions on [a href=\"http://php.net/mysql\" target=\"_blank\"]this page[/a], and i've restarted several times. PHP plays nicely with apache, mysql is cooperative through the command prompt, but PHP just can't connect to mysql. I'm sure I set up mysql and apache correctly during their installations -i manually installed php though so i don't know if I missed something there- so I must have missed something in getting them to interact

help?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 April 2006 - 08:45 AM

If you you are installing IPB2 then make sure your details yiur are entering upon installation are correct.

For now try this:
<?php

$conn = mysql_connect("localhost", "root", "rootPassword") or die("Unable to connect mysql: " mysql_error());

mysql_select_db("mysql") or die("Unable to select database: " . mysql_error());

echo "PHP was able to succesfully connect to MySQL and manage to select the mysql database too!";

?>

Before running the above code, make sure you change where it says rootPassword to the actually password your set for your mysql installation, dont use your computer username password.

Now run the code in the browser. If you get the following message:
PHP was able to succesfully connect to MySQL and manage to select the mysql database too!
Then php was able to connect to mysql and so PHP is talking to mysql and vise versa.

If you dont can you post the full error message(s) here.

#3 ember

ember
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 April 2006 - 01:49 PM

[!--quoteo(post=368328:date=Apr 25 2006, 04:45 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 25 2006, 04:45 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
If you you are installing IPB2 then make sure your details yiur are entering upon installation are correct.

For now try this:
<?php

$conn = mysql_connect("localhost", "root", "rootPassword") or die("Unable to connect mysql: " mysql_error());

mysql_select_db("mysql") or die("Unable to select database: " . mysql_error());

echo "PHP was able to succesfully connect to MySQL and manage to select the mysql database too!";

?>

Before running the above code, make sure you change where it says rootPassword to the actually password your set for your mysql installation, dont use your computer username password.

Now run the code in the browser. If you get the following message:
PHP was able to succesfully connect to MySQL and manage to select the mysql database too!
Then php was able to connect to mysql and so PHP is talking to mysql and vise versa.

If you dont can you post the full error message(s) here.
[/quote]


there is no output at all

is there some error reporting i should enable?

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 April 2006 - 03:18 PM

Oops had a slight typo in the code provided. Change this line:
$conn = mysql_connect("localhost", "root", "rootPassword") or die("Unable to connect mysql: " mysql_error());
to
$conn = mysql_connect("localhost", "root", "rootPassword") or die("Unable to connect mysql: " . mysql_error());

Also I think you have error reporting turn off. You should turn on error reporting which you can do by editing the php.ini file and finding the line that says display_errors = Off to display_errors = On

Now save your php.ini file and restart your Apache webserver.

#5 ember

ember
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 April 2006 - 09:24 PM

[!--quoteo(post=368484:date=Apr 25 2006, 11:18 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 25 2006, 11:18 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Oops had a slight typo in the code provided. Change this line:
$conn = mysql_connect("localhost", "root", "rootPassword") or die("Unable to connect mysql: " mysql_error());
to
$conn = mysql_connect("localhost", "root", "rootPassword") or die("Unable to connect mysql: " . mysql_error());

Also I think you have error reporting turn off. You should turn on error reporting which you can do by editing the php.ini file and finding the line that says display_errors = Off to display_errors = On

Now save your php.ini file and restart your Apache webserver.
[/quote]
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 3
Unable to connect mysql: Can't connect to MySQL server on 'localhost' (10061)

there you go, it's what I said from the beginning

thanks for your help so far

--RESOLVED!
I reinstalled mysql, but this time with tcp/ip connections enabled. works fine now thanks

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 April 2006 - 09:15 AM

Hi the reason why your cannt connect to mysql was becuaser mysql wasnt running and so you go the error. Whne you install MySQL you shoulf of installed it as a service this whay MySQL will start up automatically in the background when you boot into Windows.

EDIT: Oops Didn't see the following:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]--RESOLVED!
I reinstalled mysql, but this time with tcp/ip connections enabled. works fine now thanks[/quote]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users