note 70686 added to function.mysql-query

From: Date: Tue, 24 Oct 2006 00:13:31 +0000
Subject: note 70686 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-119049@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 216.194.113.175 Probable Submitter: 18.243.2.79 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/70686 Del: integrated -- https://master.php.net/note/delete/70686/integrated Del: useless -- https://master.php.net/note/delete/70686/useless Del: bad code -- https://master.php.net/note/delete/70686/bad+code Del: spam -- https://master.php.net/note/delete/70686/spam Del: non-english -- https://master.php.net/note/delete/70686/non-english Del: in docs -- https://master.php.net/note/delete/70686/in+docs Del: other reasons-- https://master.php.net/note/delete/70686 Reject -- https://master.php.net/note/reject/70686 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119049) next »