PHP won't run a complicate query, why?

时间:2015-06-15 15:00:31

标签: php mysql

i have a really strange problem.

This is a part of a .php page:

$query="SELECT idlezione, nomemateria, oinizio, ofine FROM materia, lezione, ora, giorno WHERE materia.idmateria=lezione.idmateria AND ora.idora=lezione.idora AND giorno.idgiorno=lezione.giorno AND nomegiorno=\"$nomeg\" AND iddocente=\"$docente\" AND idclasse=\"$classe\" ORDER BY oinizio;";
    echo $query;
    $res=mysql_query($query,$dbconn);
    echo mysql_num_rows($res);

Now, when i copy the result of echo $query; to phpmyadmin it returns me 2 rows, but in my .php echo mysql_num_rows($res); returns "0".

If i use a simple query like SELECT * FROM materia; it returns many rows..

UPDATE: Everything was on altervista.org, now i tried moving my db on local and running the query (using XAMPP) and everyhing works fine.. Why?

1 个答案:

答案 0 :(得分:-1)

我建议你使用PDO并准备好陈述。

这里http://docs.php.net/pdo.prepared-statements介绍了pdo和预处理语句(包括绑定参数)。