php5 mysqli multiple prepared statements sharing one mysqli instance/connection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi folks,

is it possible to have more than one prepared statement object per mysqli db connection ?

here is the pseudo code, which works, using 2 db oobjects

::--
01: $db = new MySQLi( [..] );
02: $db2 = new MySQLi( [..] );
03:
04: $select = $db->stmt_init()
05: $select->prepare("select bla from tt");
06: $select->execute();
07: $select->bind_result($BLA);
08:
09: $insert = $db2->stmt_init();
10: $insert->prepare("insert into tt2(bla) values(?)");
11: $insert->bind_param("s", $BLA);
12:
13: while($select->fetch())
14: {
15: 	$insert->execute();
16: }
::

you see, that i use a unique instance for each
prepared sql statement. everything works fine.
but i want that both statement objects share the
same db connection.

the following code will die in line 10 with wrong
number of variables at bind_param() .. if I use
a query in line 4 like "select bla from tt where id = ?"
the call of bind_param() in line 10 will be ok. but nothing
is selected, which is ok ..

::--
01: $db = new MySQLi( [..] );
02:
03: $select = $db->stmt_init()
04: $select->prepare("select bla from tt");
05: $select->execute();
06: $select->bind_result($BLA);
07:
08: $insert = $db->stmt_init();
09: $insert->prepare("insert into tt2(bla) values(?)");
10: $insert->bind_param("s", $BLA);
11:
12: while($select->fetch())
13: {
14: 	$insert->execute();
15: }
::

so I think there is problem with multiple prepared statements
internal of mysqli extension.

if you call prepare, the client goes to the server and tells the
server, that here is a new prepared statement for checking. the server tells ok
or error. if ok, the server also gives the client a ID of the prepared
statement, which he can use for future calls.

so if we call "execute()" the client goes with the ID and Params to
the server, and retrieves the results.

is it possible to have more than one prepared statement object per mysqli db connection ?

thnx.

ciao
 Mathias

--
     __________________________________________
    /
   /   http://www.phpn.org
  /  /   http://www.ltcgroup.de
 /  /  /  ____________________________
  _/ _/ _/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux