note 70686 deleted from function.mysql-query by philip

From: Date: Fri, 04 Sep 2015 19:14:55 +0000
Subject: note 70686 deleted from function.mysql-query by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203635@lists.php.net to get a copy of this message
Note Submitter: axiak at mit dot edu ---- Gconner at sgi... your function breaks when you give it a question mark! Here's a function which correctly implements what I think you want. I'm using it in a pet project of mine. The code: <?php function mysql_prepare ($query, $phs = array()) { $phs = array_map(create_function('$ph', 'return "\'".mysql_real_escape_string($ph)."\'";'), $phs); $curpos = 0; $curph = count($phs)-1; for ($i=strlen($query)-1; $i>0; $i--) { if ($query[$i] !== '?') continue; if ($curph < 0 || !isset($phs[$curph])) $query = substr_replace($query, 'NULL', $i, 1); else $query = substr_replace($query, $phs[$curph], $i, 1); $curph--; } unset($curpos, $curph, $phs); return $query; } ?>

« previous php.notes (#203635) next »