I have query below:
$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/>";
}
And in class “conn” function “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;
}
The execq function doesn’t called after some looping. The first query has been executed successfully, and then the second query being executed. After some looping, the query being stopped to called the function “conn::execq”. Any ideas? Thanks..
— EDIT —
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
And in class “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;
}
And now I’ve got:
Notice: Undefined variable: dbc in ...
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in ...
mysqli_fetch_rowon a resource after its connection has already been closed. This should not work at all.$rinside your loop, so the resource$rin yourwhilecondition will not yield any more results and the iteration ends.