note 38487 deleted from function.mysql-query by nlopess
| From: | nlopess@php.net | Date: | Wed, 24 Dec 2003 13:46:27 +0000 |
| Subject: | note 38487 deleted from function.mysql-query by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62416@lists.php.net to get a copy of this message | ||
Note Submitter: red@icuii.com
----
<?
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);