note 117826 added to mysqli.prepare
| From: | iananewton at yahoo dot com | Date: | Sat, 15 Aug 2015 15:37:34 +0000 |
| Subject: | note 117826 added to mysqli.prepare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203354@lists.php.net to get a copy of this message | ||
I've been working with prepared statements in my WP site and need to execute a variety of them.
I made up this little prepare statement function that I think is pretty rad...I wanted to have a
single function to create any basic SELECT query statement I could think of. Hopefully someone out
there can also use this? Example, I was able to arrive at the following prepared SQL statement:
SELECT * FROM tab1 INNER JOIN tab2 ON tab1.on1a = tab2.on1b INNER JOIN tab3 ON tab2.on2a = tab3.on2b
WHERE tab1.where1a = %s AND tab1.where1b = %s AND tab1.where1c = %s AND tab3.w = %s
by calling this code inside of a function
function get_foo_querystr(){
$tablearray = array(array("tab1", "tab2", "tab3"),
array("on1a", "on2a", "on3a"), array("on1b",
"on2b", "on3b"),
array(array("where1a","where1b","where1c"), "",
"where3"));
$querystr1 = "SELECT * FROM ".$tablearray[0][0];
for($x = 1; $x < count($tablearray[0]); $x++){
$querystr1.=" INNER JOIN ".$tablearray[0][$x]." ON
".$tablearray[0][$x-1].".".$tablearray[1][$x-1]." =
".$tablearray[0][$x].".".$tablearray[2][$x-1];
}
$querystr1.=" WHERE ";
for($x = 0; $x < count($tablearray[0]); $x++){
for($y = 0; $y < count($tablearray[3][$x]); $y++){
if($tablearray[3][$x]){
$querystr1.=$tablearray[0][$x].".".$tablearray[3][$x][$y]." =
"."%s"." AND ";
}
}
}
$querystr1 = chop($querystr1, " AND ");
echo $querystr1;
}
----
Server IP: 72.52.91.14
Probable Submitter: 73.213.96.27
----
Manual Page -- http://php.net/manual/en/mysqli.prepare.php
Edit -- https://master.php.net/note/edit/117826
Del: integrated -- https://master.php.net/note/delete/117826/integrated
Del: useless -- https://master.php.net/note/delete/117826/useless
Del: bad code -- https://master.php.net/note/delete/117826/bad+code
Del: spam -- https://master.php.net/note/delete/117826/spam
Del: non-english -- https://master.php.net/note/delete/117826/non-english
Del: in docs -- https://master.php.net/note/delete/117826/in+docs
Del: other reasons-- https://master.php.net/note/delete/117826
Reject -- https://master.php.net/note/reject/117826
Search -- https://master.php.net/manage/user-notes.php