note 82495 added to function.mysql-query

From: Date: Sun, 13 Apr 2008 20:46:45 +0000
Subject: note 82495 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-138278@lists.php.net to get a copy of this message
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. ---- Server IP: 208.69.120.35 Probable Submitter: 134.121.124.158 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/82495 Del: integrated -- https://master.php.net/note/delete/82495/integrated Del: useless -- https://master.php.net/note/delete/82495/useless Del: bad code -- https://master.php.net/note/delete/82495/bad+code Del: spam -- https://master.php.net/note/delete/82495/spam Del: non-english -- https://master.php.net/note/delete/82495/non-english Del: in docs -- https://master.php.net/note/delete/82495/in+docs Del: other reasons-- https://master.php.net/note/delete/82495 Reject -- https://master.php.net/note/reject/82495 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138278) next »