note 126072 added to mysqli-stmt.bind-param

From: Date: Wed, 12 May 2021 03:44:35 +0000
Subject: note 126072 added to mysqli-stmt.bind-param
Groups: php.notes 
Request: Send a blank email to php-notes+get-216376@lists.php.net to get a copy of this message
just wanted to share here, how we can use prepare statement with the combination of ... operator effectively . <?php class Database{ private function getTypeofValues($string, $value){ if(is_float($value)){ $string .= "d"; }elseif(is_integer($value)){ $string .= "i"; }elseif(is_string($value)){ $string .= "s"; }else{ $string .= "b"; } return $string; } public function makeQuery($query, array $values){ $stmt = $this->connection->prepare($query); $type = array_reduce($values, array($this, "getTypeOfValues")); $stmt->bind_param($type, ...$values); $stmt->execute(); $result = $stmt->get_result(); return $result; } } ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 2402:8100:3869:9f8c:c4fe:855e:45dc:1a17) ---- Manual Page -- https://php.net/manual/en/mysqli-stmt.bind-param.php Edit -- https://main.php.net/note/edit/126072 Del: integrated -- https://main.php.net/note/delete/126072/integrated Del: useless -- https://main.php.net/note/delete/126072/useless Del: bad code -- https://main.php.net/note/delete/126072/bad+code Del: spam -- https://main.php.net/note/delete/126072/spam Del: non-english -- https://main.php.net/note/delete/126072/non-english Del: in docs -- https://main.php.net/note/delete/126072/in+docs Del: other reasons-- https://main.php.net/note/delete/126072 Reject -- https://main.php.net/note/reject/126072 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216376) next »