note 86447 deleted from function.mysql-query by philip
| From: | philip@php.net | Date: | Fri, 04 Sep 2015 19:21:54 +0000 |
| Subject: | note 86447 deleted from function.mysql-query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203652@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Relying in external functions doesn't help you in learning programming, that is calling
external functions without having an idea of their use.
<?PHP
function mysql_queryf($string)
{
$args = func_get_args();
array_shift($args);
$len = strlen($string);
$sql_query = "";
$args_i = 0;
for($i = 0; $i < $len; $i++)
{
if($string[$i] == "%")
{
$char = $string[$i + 1];
$i++;
switch($char)
{
case "%":
$sql_query .= $char;
break;
case "u":
$sql_query .= "'" . intval($args[$args_i]) . "'";
break;
case "s":
$sql_query .= "'" . mysql_real_escape_string($args[$args_i]) .
"'";
break;
case "x":
$sql_query .= "'" . dechex($args[$args_i]) . "'";
break;
}
if($char != "x")
{
$args_i++;
}
}
else
{
$sql_query .= $string[$i];
}
}
return mysql_query($sql_query);
}
?>