New to mysqli library - Multiple query problem


Posted on 16th Feb 2014 07:03 pm by admin

Greetings,

I am writing a batch program that executes 3 queries on a single page. Using mysql libraries and regular queries works just fine. I am rewriting the page to include a stored procedure. The first query gets several thousand rows from a table, the second query calls a stored procedure which returns a resultset and the third query updates the table with the results from the stored procedure. Queries 2 & 3 are inside a while loop and execute once for every record from query 1.

Here is my connection string to the database:
$connect = mysqli_connect("localhost", "username", "password","database") or
die ("The database is unavailable. Please try again later.");

Query 1 = $results = mysqli_query($connect,$query)
Query 2 = $results1 = mysqli_query($connect,$query1);
Query 3 = $results2 = mysqli_query($connect,$query2);

$query = Select * from table
$query1 = Call stored Procedure
$query2 = Update table set ...

The above fails with this error message:
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in pagename on line 103

If I create 3 connection variables everything works as expected.
$connect = mysqli_connect("localhost", "username", "password","database") or
die ("The database is unavailable. Please try again later.");
$connect1 = mysqli_connect("localhost", "username", "password","database") or
die ("The database is unavailable. Please try again later.");
$connect2 = mysqli_connect("localhost", "username", "password","database") or
die ("The database is unavailable. Please try again later.");

Is there a way to accomplish what I am trying to do without creating 3 identical connections to the database?

I am a noob to this so go easy on my coding practices. This code actually processes 40+ records per second on an old Dell laptop

No comments posted yet

Your Answer:

Login to answer
205 Like 15 Dislike
Previous forums Next forums
Other forums

foreach iterator
Hi Guys
Does the foreach loop have an inbuilt iterator ?

How to show a complete textarea ??
I enter Client Case Notes notes in a textarea field on a PHP form. The field is 5 rows deep and 70 c

Switch letters in message (basic cryptology)...
I am trying to switch letters around in a message for an application on my site (see here). The prob

how to get values from $_Post with onchange="form.submit();"?
Hi, I have a form that submit to itself with a file upload field and two other hidden field values.<

array_count_values question?
ok i'm trying to create a top ten list from a database of listed favorite movies.

the followi

disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte

Preventing SQL Injection
I have a question about SQL Injection, In some of our code we use this: view plaincopy to clipboa

reading partial code from external site
Hi,

I am trying to write a script for my website to get an article from an external website.

Need help in log in and log out?
hi there all of u. i have recently created a site for someone. i have placed log in and log out and

mr8m - reverse document
Friends,

I'm trying to reverse a document held by MIRO, but it reports the message balan

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash