$result = mysql_query('SELECT * FROM phpfox_education_question where subject_id = 2 and ques_id =1');
var_dump($result);
//var_dump result is :- "resource(64) of type (mysql result)" in localhost and web host,but
while($row = mysql_fetch_array($result))
{
var_dump($row); //**NOTHING DISPLAYED in web host server but in localhost**
}
问问题
391 次
2 回答
0
尝试添加这个:
var_dump(mysql_num_rows($result));
要查看是否有要获取的行,如果没有,这就是您的答案。
顺便说一句,在 PDO 中,此代码如下所示:
$db = new PDO('mysql:dbname=default_db_name;host=127.0.0.1',$user,$pass);
//use prepared statmenets
$stmt = $db->prepare('SELECT * FROM your_db.phpfox_education_question WHERE subject_id = :subject_id AND ques_id = :ques_id');
//pass binds when executing the stmt
$stmt->execute(array(':subject_id' => 2, ':ques_id' => 1));
//number of rows found:
var_dump($stmt->rowCount());
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{//fetch rows as assoc array
var_dump($row);
}
请注意,这是一个基本示例,您可以使用 PDO 做更多事情
更新:
要获得更多调试信息,试试这个:
try
{
$db = new PDO();//connect, pass correct data here
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//cause PDO to throw PDOExceptions on error
$stmt = $db->prepare('SELECT * FROM your_db.phpfox_education_question WHERE subject_id = :subject_id AND ques_id = :ques_id');
$stmt->execute(array(':subject_id' => 1, ':ques_id' => 2));
var_dump($stmt->rowCount());
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
var_dump($row);
}
}
catch(PDOException $e)
{
echo $e->getMessage();
$db = null;
return;
}
echo 'No problems with query<br/>';
$db = null;//disconnecto
确保没有抛出错误,如果有,检查消息,找出问题所在并修复它。如果您找不到修复它们的方法,我们当然会为您提供帮助。
于 2012-11-05T13:01:14.357 回答
0
试试这个:
$query = "SELECT * FROM phpfox_education_question WHERE subject_id = '2' AND ques_id = '1'";
$result = mysql_query($query) or die(mysql_error()); // <--- added this
echo "Results: ".mysql_num_rows($result)."<br />"; // <--- added this to output result count
while($row = mysql_fetch_array($result))
{
print_r($row); //**NOTHING DISPLAYED in web host server but in localhost**
}
这是使用的折旧代码 btw
于 2012-11-05T12:55:45.767 回答