note 119162 added to sqlite3stmt.bindvalue

From: Date: Wed, 13 Apr 2016 00:42:27 +0000
Subject: note 119162 added to sqlite3stmt.bindvalue
Groups: php.notes 
Request: Send a blank email to php-notes+get-205218@lists.php.net to get a copy of this message
I used following logic to prepare statements, It handles both Values and Arrays ( taking help from bohwaz note) : <?php function getArgType($arg) { switch (gettype($arg)) { case 'double': return SQLITE3_FLOAT; case 'integer': return SQLITE3_INTEGER; case 'boolean': return SQLITE3_INTEGER; case 'NULL': return SQLITE3_NULL; case 'string': return SQLITE3_TEXT; default: throw new \InvalidArgumentException('Argument is of invalid type '.gettype($arg)); } } foreach ($params as $index => $val) { // indexing start from 1 in Sqlite statement if (is_array($val)) { $ok = $stmt->bindParam($index + 1, $val); } else { $ok = $stmt->bindValue($index + 1, $val, getArgType($val)); } if (!$ok) { throw new Exception("Unable to bind param: $val"); } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 1.22.216.67 ---- Manual Page -- http://php.net/manual/en/sqlite3stmt.bindvalue.php Edit -- https://master.php.net/note/edit/119162 Del: integrated -- https://master.php.net/note/delete/119162/integrated Del: useless -- https://master.php.net/note/delete/119162/useless Del: bad code -- https://master.php.net/note/delete/119162/bad+code Del: spam -- https://master.php.net/note/delete/119162/spam Del: non-english -- https://master.php.net/note/delete/119162/non-english Del: in docs -- https://master.php.net/note/delete/119162/in+docs Del: other reasons-- https://master.php.net/note/delete/119162 Reject -- https://master.php.net/note/reject/119162 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205218) next »