Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:57:54+00:00 2026-06-09T15:57:54+00:00

I have query below: $r = Query goes here…; $r = conn::execq($q); while($fetch =

  • 0

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 ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:57:55+00:00Added an answer on June 9, 2026 at 3:57 pm
    1. You are opening and closing the database connection several times in very short order; this is horribly inefficient. Keep reusing one open connection!
    2. You are trying to use mysqli_fetch_row on a resource after its connection has already been closed. This should not work at all.
    3. You are overwriting the resource $r inside your loop, so the resource $r in your while condition will not yield any more results and the iteration ends.
    4. You should try to make one slightly more complex SQL query to get the information you want instead of generating more and more queries by looping over the result of the first query. The database can often do much more work for you than you think.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query below that I use to retrieve the records not updated
We have the query below. Using a LEFT OUTER join takes 9 seconds to
I have the query below that when run it says that 325 rows were
I have below query I am trying to show message 'No SubSource for this
I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
I have an SQL query (below) that essentially takes a student from tbStudents, and
The query below returns rows that have both loginid and ip2 in the bumps
I have the below query in a postgresql database SELECT * FROM accounts where
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I get the following error in the query below: #1064 - You have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.