Log in

View Full Version : Multiple queries on one mysqli object?



Cronos
04-16-2008, 12:10 PM
I'm still new to MySQL/PHP. The book I've ordered hasen't arrived yet, and I am eager to learn. :P

Now, here's the problem:

Is it possible to have multilpe queries on one mysqli object?

I found some code, and tried amending it, but it doesn't work.
I get Fatal error: Call to a member function query() on a non-object in /home/.mohave/tetest/<mysite>/ex/table2b.php on line 35
which leads me to believe that the "object" somehow closes connection with the db after one query.
Also, with my setup I cannot use $result.close() to "release" the connection.



$connect = new mysqli("....")

$query = "SELECT
* ..."

$result = $connect->query($query)

function f1() {

$query_a = "SELECT.."
$results_a = $connect->query($query_a) <-- line 35
..do something...
}

function f2() {

$query_b = "SELECT.."
$results_b = $connect->query($query_b)
..do something...
}

while($row = $result->fetch_array(MYSQLI_ASSOC))
{
f1(some parameter from $row)
f2(another parameter from $row)
...do something more...
}

codeexploiter
04-16-2008, 12:19 PM
Make sure that you are connected to the database properly before executing any queries. Here is a step-by-step tutorial about the PHP-MySql interaction

http://www.php-mysql-tutorial.com/

Cronos
04-16-2008, 12:45 PM
I'm quite sure I am connected b/c the first query doesn't yield any errors, and I'm also able to get a quantitative response (I'm able to get num_rows).

Cronos
04-16-2008, 04:41 PM
I've partly figured it out.
It's a question of scope.
I supposedly need to globally declare variables within functions.

http://www.phpbuilder.com/board/showthread.php?t=10308946

Well. I'm still learning. :)