note 117826 deleted from mysqli.prepare by googleguy

From: Date: Sat, 15 Aug 2015 20:41:30 +0000
Subject: note 117826 deleted from mysqli.prepare by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203359@lists.php.net to get a copy of this message
Note Submitter: iananewton at yahoo dot com ---- 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; }

« previous php.notes (#203359) next »