note 38487 added to function.mysql-query

From: Date: Tue, 23 Dec 2003 19:59:36 +0000
Subject: note 38487 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-62388@lists.php.net to get a copy of this message
<? function mysql_queryf() { function validate($a, $b) { if ($a == "s") return "'".mysql_escape_string($b)."'"; if ($a == "d") return (int)$b; if ($a == "f") return (float)$b; return "''"; } $args = func_get_args(); if (count($args) < 1) return; $i = 0; $fmt = array_shift($args); $query = preg_replace("/%(s|d|f)/e", 'validate("$1", $args[$i++])', $fmt, count($args)); return mysql_query($query); } ?> Here's my mysql_queryf Works kind of like printf mysql_queryf("select * from a where name=%s and age=%d", "mike", 24); ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38487 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38487&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38487&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62388) next »