diff --git a/composer.json b/composer.json index c5718e9..43afb23 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "colshrapnel/safemysql", "description": "A real safe and convenient way to handle MySQL queries.", "type": "library", - "version": "0.0.1", + "version": "1.0.0", "keywords": [ "db", "mysql" diff --git a/safemysql.class.php b/safemysql.class.php index 7c2df96..44623aa 100644 --- a/safemysql.class.php +++ b/safemysql.class.php @@ -26,7 +26,7 @@ * and * ?p ("parsed") - special type placeholder, for inserting already parsed statements without any processing, to avoid double parsing. * - * Some examples: + * Connection: * * $db = new SafeMySQL(); // with default settings * @@ -38,6 +38,13 @@ * ); * $db = new SafeMySQL($opts); // with some of the default settings overwritten * + * Alternatively, you can just pass an existing mysqli instance that will be used to run queries + * instead of creating a new connection. + * Excellent choice for migration! + * + * $db = new SafeMySQL(['mysqli' => $mysqli]); + * + * Some examples: * * $name = $db->getOne('SELECT name FROM table WHERE id = ?i',$_GET['id']); * $data = $db->getInd('id','SELECT * FROM ?n WHERE id IN ?a','table', array(1,2)); @@ -76,7 +83,7 @@ class SafeMySQL 'socket' => NULL, 'pconnect' => FALSE, 'charset' => 'utf8', - 'errmode' => 'error', //or exception + 'errmode' => 'exception', //or 'error' 'exception' => 'Exception', //Exception class name ); @@ -90,6 +97,19 @@ class SafeMySQL $this->emode = $opt['errmode']; $this->exname = $opt['exception']; + if (isset($opt['mysqli'])) + { + if ($opt['mysqli'] instanceof mysqli) + { + $this->conn = $opt['mysqli']; + return; + + } else { + + $this->error("mysqli option must be valid instance of mysqli class"); + } + } + if ($opt['pconnect']) { $opt['host'] = "p:".$opt['host'];