Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ...可以正确的得到结果,但是有warning!是什么 这个提示就是result不对啊。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phpclass MySQL { var $obj = array ( "sql_database" => "" , "sql_user" => "root" , "sql_pass" => "" , "sql_host" => "localhost", "sql_port" => "" , "persistent" => "1" , "cached_queries" => array(), 'debug' => 0, ); var $database = ""; var $query_id = ""; var $connection_id = ""; var $query_count = 0; var $record_row = array(); var $return_die = 0; var $error = ""; /*========================================================================*/ // Construtor /*========================================================================*/ function MySQL($host, $db, $user, $password, $persistent, $hideError=1) { $this->obj = array ( "sql_database" => $db , "sql_user" => $user , "sql_pass" => $password , "sql_host" => $host, "sql_port" => "" , "persistent" => $persistent , "cached_queries" => array(), 'debug' => 0, ); $this->database = $db; $this->return_die = $hideError; } function query($the_query, $bypass=0) { $this->query_id = mysql_query($the_query, $this->connection_id); if (! $this->query_id ) { $this->fatal_error("mySQL query error: $the_query"); } if ($this->obj['debug']) { $endtime = $Debug->endTimer(); if ( preg_match( "/^select/i", $the_query ) ) { $eid = mysql_query("EXPLAIN $the_query", $this->connection_id); echo "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FFE8F3' align='center'> <tr> <td colspan='8' style='font-size:14px' bgcolor='#FFC5Cb'><b>Select Query</b></td> </tr> <tr> <td colspan='8' style='font-family:courier new, courier, monaco, arial;font-size:14px'>$the_query</td> </tr> <tr bgcolor='#FFC5Cb'> <td><b>table</b></td><td><b>type</b></td><td><b>possible_keys</b></td> <td><b>key</b></td><td><b>key_len</b></td><td><b>ref</b></td> <td><b>rows</b></td><td><b>Extra</b></td> </tr>\n"; while( $array = mysql_fetch_array($eid) ) { $type_col = '#FFFFFF'; if ($array['type'] == 'ref' or $array['type'] == 'eq_ref' or $array['type'] == 'const') { $type_col = '#D8FFD4'; } else if ($array['type'] == 'ALL') { $type_col = '#FFEEBA'; } echo "<tr bgcolor='#FFFFFF'> <td>$array[table] </td> <td bgcolor='$type_col'>$array[type] </td> <td>$array[possible_keys] </td> <td>$array[key] </td> <td>$array[key_len] </td> <td>$array[ref] </td> <td>$array[rows] </td> <td>$array[Extra] </td> </tr>\n"; } if ($endtime > 0.1) { $endtime = "<span style='color:red'><b>$endtime</b></span>"; } echo "<tr> <td colspan='8' bgcolor='#FFD6DC' style='font-size:14px'><b>mySQL time</b>: $endtime</b></td> </tr> </table>\n<br />\n"; } else { echo "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE' align='center'> <tr> <td style='font-size:14px' bgcolor='#EFEFEF'><b>Non Select Query</b></td> </tr> <tr> <td style='font-family:courier new, courier, monaco, arial;font-size:14px'>$the_query</td> </tr> <tr> <td style='font-size:14px' bgcolor='#EFEFEF'><b>mySQL time</b>: $endtime</span></td> </tr> </table><br />\n\n"; } } $this->query_count++; $this->obj['cached_queries'][] = $the_query; return $this->query_id; } function get_num_rows($query_id="") { if ($query_id == "") { $query_id = $this->query_id; } return mysql_num_rows($query_id); }。?> $query = "select id, name, fileName from InfoAttachment where infoId=$id and type='file'";$res = $db->query($query);$num_rows=$db->get_num_rows();$num_rows可以得到正确的值! header("location".$url)不能用于if语句中? 对文件的操作 php下如何安装openssl 怎么在电脑里面同时安装商城的程序和另外一个discuz的程序? eclipse的php插件对html代码不能格式化吗?缩进这些 PHP获得前台Post上来的变量的问题 初学PHP,请问,PHP5页面间的参数怎么传递? 小问题大送分,关于数据打印 只有几行php代码,帮忙看看(我没分了:() 帮我看看用什么函数可以实行下面的结果 session问题 关于session使用的小问题
class MySQL { var $obj = array ( "sql_database" => "" ,
"sql_user" => "root" ,
"sql_pass" => "" ,
"sql_host" => "localhost",
"sql_port" => "" ,
"persistent" => "1" ,
"cached_queries" => array(),
'debug' => 0,
);
var $database = "";
var $query_id = "";
var $connection_id = "";
var $query_count = 0;
var $record_row = array();
var $return_die = 0;
var $error = "";
/*========================================================================*/
// Construtor
/*========================================================================*/
function MySQL($host, $db, $user, $password, $persistent, $hideError=1) {
$this->obj = array ( "sql_database" => $db ,
"sql_user" => $user ,
"sql_pass" => $password ,
"sql_host" => $host,
"sql_port" => "" ,
"persistent" => $persistent ,
"cached_queries" => array(),
'debug' => 0,
);
$this->database = $db;
$this->return_die = $hideError;
}
function query($the_query, $bypass=0) {
$this->query_id = mysql_query($the_query, $this->connection_id);
if (! $this->query_id )
{
$this->fatal_error("mySQL query error: $the_query");
}
if ($this->obj['debug'])
{
$endtime = $Debug->endTimer();
if ( preg_match( "/^select/i", $the_query ) )
{
$eid = mysql_query("EXPLAIN $the_query", $this->connection_id);
echo "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FFE8F3' align='center'>
<tr>
<td colspan='8' style='font-size:14px' bgcolor='#FFC5Cb'><b>Select Query</b></td>
</tr>
<tr>
<td colspan='8' style='font-family:courier new, courier, monaco, arial;font-size:14px'>$the_query</td>
</tr>
<tr bgcolor='#FFC5Cb'>
<td><b>table</b></td><td><b>type</b></td><td><b>possible_keys</b></td>
<td><b>key</b></td><td><b>key_len</b></td><td><b>ref</b></td>
<td><b>rows</b></td><td><b>Extra</b></td>
</tr>\n";
while( $array = mysql_fetch_array($eid) )
{
$type_col = '#FFFFFF';
if ($array['type'] == 'ref' or $array['type'] == 'eq_ref' or $array['type'] == 'const')
{
$type_col = '#D8FFD4';
}
else if ($array['type'] == 'ALL')
{
$type_col = '#FFEEBA';
}
echo "<tr bgcolor='#FFFFFF'>
<td>$array[table] </td>
<td bgcolor='$type_col'>$array[type] </td>
<td>$array[possible_keys] </td>
<td>$array[key] </td>
<td>$array[key_len] </td>
<td>$array[ref] </td>
<td>$array[rows] </td>
<td>$array[Extra] </td>
</tr>\n";
}
if ($endtime > 0.1)
{
$endtime = "<span style='color:red'><b>$endtime</b></span>";
}
echo "<tr>
<td colspan='8' bgcolor='#FFD6DC' style='font-size:14px'><b>mySQL time</b>: $endtime</b></td>
</tr>
</table>\n<br />\n";
}
else
{
echo "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE' align='center'>
<tr>
<td style='font-size:14px' bgcolor='#EFEFEF'><b>Non Select Query</b></td>
</tr>
<tr>
<td style='font-family:courier new, courier, monaco, arial;font-size:14px'>$the_query</td>
</tr>
<tr>
<td style='font-size:14px' bgcolor='#EFEFEF'><b>mySQL time</b>: $endtime</span></td>
</tr>
</table><br />\n\n";
}
}
$this->query_count++;
$this->obj['cached_queries'][] = $the_query;
return $this->query_id;
}
function get_num_rows($query_id="") {
if ($query_id == "")
{
$query_id = $this->query_id;
}
return mysql_num_rows($query_id);
}
。
?>
$res = $db->query($query);
$num_rows=$db->get_num_rows();
$num_rows可以得到正确的值!