mySQL query works, but returns false in PHP
Posted: Tue Aug 24, 2010 12:28 pm
This buggered me an hour last night, maybe someone can tell me what I'm doing wrong. The query fails, with no error. I am connecting properly I believe. This is uber simple so what the heck am I doing wrong. I took the query from phpmyadmin where it returns results properly. This has to be something really simple, but since Im relatively new to php/mySQL I expect to be schooled quickly. Thanks.
Code: Select all
$dbhandle = mysql_connect('localhost', 'root', 'password') or die(mysql_error());
$link = mysql_select_db('exp', $dbhandle) ;
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully ';
$query = 'SELECT * FROM `uidhistory` WHERE `UID` = 1 LIMIT 0, 30 ';
$result = mysql_query($query, $link);
if (!$result) {
mysql_error();
die('Could not query:' . mysql_error());
}
echo $result;
$num_rows = mysql_num_rows($result);
echo $num_rows;