note 71987 added to function.mysqli-stmt-store-result
| From: | Typer85 at gmail dot com | Date: | Wed, 27 Dec 2006 23:58:09 +0000 |
| Subject: | note 71987 added to function.mysqli-stmt-store-result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120967@lists.php.net to get a copy of this message | ||
In response to the note below me for the claim that mysqli_fetch_fields is not compatible with
prepared statements.
This is untrue, it is but you have to do a little extra work. I would recommend you use a wrapper
function of some sort to take care of the dirty business for you but the basic idea is the same.
Let's assume you have a prepared statement like so. I am going to use the procedural way for
simplicity but the same idea can be done using the object oriented way:
<?php
// Connect Blah Blah Blah.
$connectionLink = mysqli_connect( .... );
// Query Blab Blah Blah.
$query = "Select
Id From Table Where Id = ?";
// Prepare Query.
$prepareObject = mysqli_prepare( $connectionLink , $query );
// Bind Query.
mysqli_stmt_bind_param( $prepareObject , 'i' , 1 );
// Execute Query.
mysqli_stmt_execute( $prepareObject );
?>
Now all the above is fine and dandy to anyone familiar with using prepared statements, but if I want
to use mysqli_fetch_fields or any other function that fetches meta information about a result set
but does not work on prepared statements?
Enter the special function mysqli_stmt_result_metadata. It can be used as follows, assume the
following code segment immediatley follows that of the above code segment.
<?php
$metaData = mysqli_stmt_result_metadata( $prepareObject );
// I Can Now Call mysqli_fetch_fields using the variable
// $metaData as an argument.
$fieldInfo = mysqli_fetch_fields( $metaData );
// Or Even This.
$fieldInfo = mysqli_num_fields( $metaData );
?>
Take a look at the Manual entry for mysqli_stmt_result_metatdata function for full details on how to
expose it with prepared statements.
Good Luck,
----
Server IP: 66.163.161.117
Probable Submitter: 84.36.231.206
----
Manual Page -- http://www.php.net/manual/en/function.mysqli-stmt-store-result.php
Edit -- https://master.php.net/note/edit/71987
Del: integrated -- https://master.php.net/note/delete/71987/integrated
Del: useless -- https://master.php.net/note/delete/71987/useless
Del: bad code -- https://master.php.net/note/delete/71987/bad+code
Del: spam -- https://master.php.net/note/delete/71987/spam
Del: non-english -- https://master.php.net/note/delete/71987/non-english
Del: in docs -- https://master.php.net/note/delete/71987/in+docs
Del: other reasons-- https://master.php.net/note/delete/71987
Reject -- https://master.php.net/note/reject/71987
Search -- https://master.php.net/manage/user-notes.php