我在下面查询:
$r = "Query goes here...";
$r = conn::execq($q);
while($fetch = mysqli_fetch_array($r)) {
$q = "Query goes here..."; //The $fetch value above is inserted here as 'WHERE' clause
$r = conn::execq($q); //--> The problem
$r = mysqli_fetch_row($r);
if($r > 0) print "ok<br/>";
else print "failed<br/>";
}
在课程“ conn ”中,功能“ execq ”:
public static function execq($q) {
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
$r = mysqli_query($dbc, $q);
mysqli_close($dbc);
return $r;
}
在某些循环后,不会调用 execq 函数。第一个查询已成功执行,然后执行第二个查询。在一些循环之后,查询被停止以调用函数“conn :: execq”。有任何想法吗?感谢..
---编辑---
conn:openconn(); //Open connection
$r = "Query goes here...";
$r = conn::execq($q);
while($fetch = mysqli_fetch_array($r)) {
$q = "Query goes here..."; //The $fetch value above is inserted here as 'WHERE' clause
$r = conn::execq($q); //--> The problem
$r = mysqli_fetch_row($r);
if($r > 0) print "ok<br/>";
else print "failed<br/>";
}
conn:closeconn(); //Close connection
在课堂上“ conn ”:
public static function openconn() {
global $dbc;
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
}
public static function closeconn() {
mysqli_close($dbc);
}
public static function execq($q) {
$r = mysqli_query($dbc, $q);
return $r;
}
现在我有了:
Notice: Undefined variable: dbc in ...
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in ...
答案 0 :(得分:2)
mysqli_fetch_row
。这根本不起作用。$r
,因此$r
条件中的资源while
将不会再产生任何结果,并且迭代结束。