note 126071 added to mysqli.prepare

From: Date: Wed, 12 May 2021 03:41:56 +0000
Subject: note 126071 added to mysqli.prepare
Groups: php.notes 
Request: Send a blank email to php-notes+get-216375@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.prepare.php Edit -- https://main.php.net/note/edit/126071 Del: integrated -- https://main.php.net/note/delete/126071/integrated Del: useless -- https://main.php.net/note/delete/126071/useless Del: bad code -- https://main.php.net/note/delete/126071/bad+code Del: spam -- https://main.php.net/note/delete/126071/spam Del: non-english -- https://main.php.net/note/delete/126071/non-english Del: in docs -- https://main.php.net/note/delete/126071/in+docs Del: other reasons-- https://main.php.net/note/delete/126071 Reject -- https://main.php.net/note/reject/126071 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216375) next »