Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mysql connection problem on local machine

Status
Not open for further replies.

baza

Programmer
May 15, 2001
20
ES
Hi ,

I have managed(after lots of trying) to install mysql and php and apache on a pc running windows xp

I can access mysql via phpmyadmin and have imported a db into it

everything is fine but i am unable to connect to the mysql db via php

I am using the same code(that works perfectly on a domain host(with host username and password changed of course))but I keep getting errors

I tried connecting with this code

<?

$dbh=mysql_connect ("localhost", "root", "admin") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("motorcro_moto");

$query="SELECT * FROM admin";

$result = mysql_query($query) or die("Could not run query.");
$numrows = mysql_num_rows($result);

echo "numrows=".$numrows;

?>

but when I run it it returns

Could not run query.

has anyone got any idea where the problem my be. i am happy to post the php.ini and the httpd.conf if that helps


I am tearing my hair out as I am so close(after taking 8 hours to get phpmyadmin working)

thanks in advance

 
Try adding a mysql_error() to the die clause in your mysql_query call, as it seems its not the connection but the actual query.

Code:
$result = mysql_query($query) or die("Could not run query because: " . mysql_error());



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
done that and the response is

Could not run query because: No database selected

but as you can see in the code the db is
mysql_select_db ("motorcro_moto");
 
Actually, the select db should be in the form of:

Code:
$db=mysql_select_db("dbname",$dbconn) or die(mysql_error());

Learn to use the mysql_error() function after any mysql call. It one of the ways to know what is going on with the call if it doesn't work as expected.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thanks all sorted.

I knew I was pretty close.

Thats a couple of grey hairs less

cheers
 
Glad to have helped.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Glad you got it going. When ever you run into a problem, put the die() & error code after your mysql_select_db and mysql_query also.

Sam
;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top