mysqli_stmt_bind_result

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

 



Hi folks,
I've got a question concerning an upgrade from mysql to mysqli using 
prepared statements.
Back then wit hmysql we used something like this:

$sqlst="SELECT * FROM table WHERE itemid='$_GET[itemid]'";
$result=mysql_query($sqlst);
$row=mysql_fetch_array($result);

What we got out of this was an array with indices named just like the 
database fields.

When transscribing  the above to mysqli with prepared statements I tried the 
following:

$li = new mysqli("localhost", "my_user", "my_password", "my_database");
$sqlst="SELECT * FROM table WHERE itemid=?";
$stmt = mysqli_prepare($li, $sqlst);
mysqli_stmt_bind_param($stmt, 's', $_GET[itemid]);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $row);

According to the PHP manual it's quite normal that the above throws an error 
message, because mysqli_stmt_bind_result() expects one variable for each 
database field that you selected. If you just select a few fields from your 
database that's perfectly ok, but if you select something like 20 fields 
this can be really annoying.
Is there a way to make the above work like in the "old" version, meaning 
fetching the result of mysqli_stmt_execute() into into an array that has its 
indices automagically named like the according database fields just like 
mysql_fetch_array() does?

Any help would be very much appreciated.

-- 
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