Browse Source

Merge pull request #32 from colshrapnel/dev

Dev
binary-test 1.0.0
colshrapnel 10 years ago
parent
commit
9360eabc1c
  1. 2
      composer.json
  2. 24
      safemysql.class.php

2
composer.json

@ -2,7 +2,7 @@
"name": "colshrapnel/safemysql", "name": "colshrapnel/safemysql",
"description": "A real safe and convenient way to handle MySQL queries.", "description": "A real safe and convenient way to handle MySQL queries.",
"type": "library", "type": "library",
"version": "0.0.1", "version": "1.0.0",
"keywords": [ "keywords": [
"db", "db",
"mysql" "mysql"

24
safemysql.class.php

@ -26,7 +26,7 @@
* and * and
* ?p ("parsed") - special type placeholder, for inserting already parsed statements without any processing, to avoid double parsing. * ?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 * $db = new SafeMySQL(); // with default settings
* *
@ -38,6 +38,13 @@
* ); * );
* $db = new SafeMySQL($opts); // with some of the default settings overwritten * $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']); * $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)); * $data = $db->getInd('id','SELECT * FROM ?n WHERE id IN ?a','table', array(1,2));
@ -76,7 +83,7 @@ class SafeMySQL
'socket' => NULL, 'socket' => NULL,
'pconnect' => FALSE, 'pconnect' => FALSE,
'charset' => 'utf8', 'charset' => 'utf8',
'errmode' => 'error', //or exception 'errmode' => 'exception', //or 'error'
'exception' => 'Exception', //Exception class name 'exception' => 'Exception', //Exception class name
); );
@ -90,6 +97,19 @@ class SafeMySQL
$this->emode = $opt['errmode']; $this->emode = $opt['errmode'];
$this->exname = $opt['exception']; $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']) if ($opt['pconnect'])
{ {
$opt['host'] = "p:".$opt['host']; $opt['host'] = "p:".$opt['host'];

Loading…
Cancel
Save