note 107202 deleted from mysqli.prepare by danbrown
| From: | danbrown@php.net | Date: | Sat, 14 Jan 2012 16:23:02 +0000 |
| Subject: | note 107202 deleted from mysqli.prepare by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185654@lists.php.net to get a copy of this message | ||
Note Submitter: Darren
----
My previous post had errors in the examples, it should look like what is below. Pardon for the
spam, but it should be worth your time:
Example(s):
For a table of firstName and lastName:
John Smith
Mark Smith
Jack Johnson
Bob Johnson
<?php
//single query, single result
$query = "SELECT * FROM names WHERE firstName=? AND lastName=?";
$params = array("Bob","Johnson");
mysqli_prepared_query($link,$query,"ss",$params)
/*
returns array(
0=> array('firstName' => 'Bob', 'lastName' =>
'Johnson')
)
*/
//single query, multiple results
$query = "SELECT * FROM names WHERE lastName=?";
$params = array("Smith");
mysqli_prepared_query($link,$query,"s",$params)
/*
returns array(
0=> array('firstName' => 'John', 'lastName' =>
'Smith')
1=> array('firstName' => 'Mark', 'lastName' =>
'Smith')
)
*/
//multiple query, multiple results
$query = "SELECT * FROM names WHERE lastName=?";
$params = array(array("Smith"),array("Johnson"));
mysqli_prepared_query($link,$query,"s",$params)
/*
returns array(
0=>
array(
0=> array('firstName' => 'John', 'lastName' =>
'Smith')
1=> array('firstName' => 'Mark', 'lastName' =>
'Smith')
)
1=>
array(
0=> array('firstName' => 'Jack', 'lastName' =>
'Johnson')
1=> array('firstName' => 'Bob', 'lastName' =>
'Johnson')
)
)
*/
Hope it helps =)