note 114834 deleted from function.implode by peehaa

From: Date: Sun, 28 Apr 2019 10:49:50 +0000
Subject: note 114834 deleted from function.implode by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210822@lists.php.net to get a copy of this message
Note Submitter: Jacques Amar ---- Safe way to pass as parameters in IN <?php $id_nums = array(1,6,12,18,24); $p_types = ''; $qs = array(); foreach ($id_nums as $id) { $qs[] = '?'; $p_types .= 'i'; // or whatever type } $nums_list = implode(',', $qs); $sqlquery = "Select name,email,phone from usertable where user_id IN ($nums_list)"; $stmt = $dbh->stmt_init(); $stmt->prepare($sqlquery); // later on, instead of bind: $parms_array = array_merge(array($p_types), $id_nums); call_user_func_array(array($stmt,'bind_param'), $parms_array ); // $sqlquery becomes "Select name,email,phone from usertable where user_id IN (?,?,?,?,?)" ?>

« previous php.notes (#210822) next »