note 80708 added to function.mysqli-query
| From: | mail at willboyce dot com | Date: | Tue, 29 Jan 2008 19:36:50 +0000 |
| Subject: | note 80708 added to function.mysqli-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135561@lists.php.net to get a copy of this message | ||
I have extended mysqli and taken query() a step further, as I was tired of forever escaping strings
before putting them in a database. queryf() emulates sprintf() style formatting, performing extra
sanitization on strings (%s).
<?php
...
public function squeryf() {
$argv = func_get_args();
if (is_array($argv[0]))
$argv = $argv[0];
$qry = array_shift($argv);
$matches = array();
$percents = preg_match_all("/(%[+-]{0,1}[-]{0,1}[\d]{0,}[bcdeufFosxX]{1})/", $qry,
$matches);
foreach($matches[1] as $match) {
$arg = array_shift($argv);
if ($match=="%s")
$arg = $this->real_escape_string(strip_tags($arg,
implode($this->allowed_tags)));
$qry = preg_replace("/$match/", sprintf($match, $arg), $qry, 1);
}
return $qry;
}
...
?>
The full class can be found at http://blog.willboyce.com/2008/01/29/mysqli2/
--
Regards, Will Boyce
http://willboyce.com
----
Server IP: 194.145.210.3
Probable Submitter: 87.194.110.175
----
Manual Page -- http://www.php.net/manual/en/function.mysqli-query.php
Edit -- https://master.php.net/note/edit/80708
Del: integrated -- https://master.php.net/note/delete/80708/integrated
Del: useless -- https://master.php.net/note/delete/80708/useless
Del: bad code -- https://master.php.net/note/delete/80708/bad+code
Del: spam -- https://master.php.net/note/delete/80708/spam
Del: non-english -- https://master.php.net/note/delete/80708/non-english
Del: in docs -- https://master.php.net/note/delete/80708/in+docs
Del: other reasons-- https://master.php.net/note/delete/80708
Reject -- https://master.php.net/note/reject/80708
Search -- https://master.php.net/manage/user-notes.php