Skip to content

Commit

Permalink
Merge pull request #32 from colshrapnel/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
colshrapnel committed May 8, 2015
2 parents 9cdfd4e + 03b9f2b commit 9360eab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 22 additions & 2 deletions safemysql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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));
Expand Down Expand Up @@ -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
);

Expand All @@ -90,6 +97,19 @@ function __construct($opt = array())
$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'];
Expand Down

0 comments on commit 9360eab

Please sign in to comment.