I have come to the following problem. My code is like this:
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
mysql_select_db($mysql_database,$dbhandle);
$today = date('Y-m-d');
$queryfirst = "SELECT * FROM `database`.`sm2014` WHERE pvm='$today'";
echo $queryfirst;
$result = mysql_query("$queryfirst")|| die(mysql_error());
//fetch tha data from the database
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $queryfirst;
die($message);
}
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
$num_rows = mysql_num_rows($result);
My output on page is:
Connected to MySQL
SELECT * FROM `database`.`sm2014` WHERE pvm='2014-12-09'
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /*path*/2014/index.php on line 86
So, i get no Error, i tried to copy-paste-run mysql query that is generated by php in PhpMyAdmin and it works perfectly. I have tried different queries:
SELECT * FROM `database`.`sm2014` WHERE pvm='2014-12-09'
SELECT * FROM `database`.`sm2014` WHERE pvm=2014-12-09
SELECT * FROM sm2014 WHERE pvm='2014-12-09'
SELECT * FROM `sm2014` WHERE pvm='2014-12-09'
And also different combinations of them, still it doesnt work. I have tried just put in php page this query:
$queryfirst = "SELECT * FROM `database`.`sm2014` WHERE pvm='2014-12-09'";
and it also gives error. In database pvm is DATE type.