note 82495 deleted from function.mysql-query by philip
| From: | philip@php.net | Date: | Fri, 04 Sep 2015 19:22:29 +0000 |
| Subject: | note 82495 deleted from function.mysql-query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203656@lists.php.net to get a copy of this message | ||
Note Submitter: uramihsayibok, gmail, com
----
Similar to the queryf() posted by sk89q, I've found this small function quite handy.
Just please, please, PLEASE remember to escape your strings!
<?php
function mysql_queryf($query) {
if (func_num_args()>1) {
$args=func_get_args();
$query=call_user_func_array("sprintf",$args);
}
return mysql_query($query);
}
// Allows for things like
$resultset=mysql_queryf("SELECT * FROM
table WHERE id=%u LIMIT
1", $_GET["id"]);
// $_GET["id"] will be converted to an integer: 0 if it's invalid
?>
With a little modification it can handle a $connection resource too.