Commit c28a3d24 authored by Alexander Butenko's avatar Alexander Butenko

Merge pull request #277 from avbdr/master

update readme
parents 04cc2db5 35cc763c
...@@ -334,7 +334,7 @@ class dbObject { ...@@ -334,7 +334,7 @@ class dbObject {
* *
* @access public * @access public
* @param integer|array $limit Array to define SQL limit in format Array ($count, $offset) * @param integer|array $limit Array to define SQL limit in format Array ($count, $offset)
or only $count * or only $count
* @param array|string $fields Array or coma separated list of fields to fetch * @param array|string $fields Array or coma separated list of fields to fetch
* *
* @return array Array of dbObjects * @return array Array of dbObjects
......
...@@ -7,7 +7,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements ...@@ -7,7 +7,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
**[Update Query](#update-query)** **[Update Query](#update-query)**
**[Select Query](#select-query)** **[Select Query](#select-query)**
**[Delete Query](#delete-query)** **[Delete Query](#delete-query)**
**[Generic Query](#generic-query-method)** **[Running raw SQL queries](#running-raw-sql-queries)**
**[Query Keywords](#query-keywords)** **[Query Keywords](#query-keywords)**
**[Raw Query](#raw-query-method)** **[Raw Query](#raw-query-method)**
**[Where Conditions](#where-method)** **[Where Conditions](#where-method)**
...@@ -53,9 +53,10 @@ $db = new MysqliDb (Array ( ...@@ -53,9 +53,10 @@ $db = new MysqliDb (Array (
'password' => 'password', 'password' => 'password',
'db'=> 'databaseName', 'db'=> 'databaseName',
'port' => 3306, 'port' => 3306,
'prefix' => 'my_',
'charset' => 'utf8')); 'charset' => 'utf8'));
``` ```
port and charset params are optional. prefix, port and charset params are optional.
Reuse already connected mysqli: Reuse already connected mysqli:
```php ```php
...@@ -63,11 +64,24 @@ $mysqli = new mysqli ('host', 'username', 'password', 'databaseName'); ...@@ -63,11 +64,24 @@ $mysqli = new mysqli ('host', 'username', 'password', 'databaseName');
$db = new MysqliDb ($mysqli); $db = new MysqliDb ($mysqli);
``` ```
Its also possible to set a table prefix: Its also possible to set a table prefix via separate call:
```php ```php
$db->setPrefix ('my_'); $db->setPrefix ('my_');
``` ```
If you need to get already created mysqliDb object from another class or function use
```php
function init () {
// db staying private here
$db = new MysqliDb ('host', 'username', 'password', 'databaseName');
}
function myfunc () {
// obtain db object created in init ()
$db = MysqliDb::getInstance();
...
}
```
Next, prepare your data, and call the necessary methods. Next, prepare your data, and call the necessary methods.
### Objects mapping ### Objects mapping
...@@ -110,7 +124,7 @@ else ...@@ -110,7 +124,7 @@ else
``` ```
### Replace Query ### Replace Query
replace() method implements same API as insert(); <a href='https://dev.mysql.com/doc/refman/5.0/en/replace.html'>Replace()</a> method implements same API as insert();
### Update Query ### Update Query
```php ```php
...@@ -176,21 +190,13 @@ echo $u->login; ...@@ -176,21 +190,13 @@ echo $u->login;
// Json return type // Json return type
$json = $db->JsonBuilder()->getOne("users"); $json = $db->JsonBuilder()->getOne("users");
``` ```
### Delete Query
```php
$db->where('id', 1);
if($db->delete('users')) echo 'successfully deleted';
```
### Generic Query Method
By default rawQuery() will filter out special characters so if you getting problems with it
you might try to disable filtering function. In this case make sure that all external variables are passed to the query via bind variables
### Running raw SQL queries
```php ```php
// filtering enabled // filtering enabled
$users = $db->rawQuery('SELECT * from users where customerId=?', Array (10)); $users = $db->rawQuery('SELECT * from users where customerId=?', Array (10));
// filtering disabled // filtering disabled
//$users = $db->rawQuery('SELECT * from users where id >= ?', Array (10), false); //$users = $db->rawQuery('SELECT * from users where id >= ?', Array (10));
foreach ($users as $user) { foreach ($users as $user) {
print_r ($user); print_r ($user);
} }
...@@ -336,6 +342,13 @@ $results = $db ...@@ -336,6 +342,13 @@ $results = $db
->get('users'); ->get('users');
``` ```
### Delete Query
```php
$db->where('id', 1);
if($db->delete('users')) echo 'successfully deleted';
```
### Ordering method ### Ordering method
```php ```php
$db->orderBy("id","asc"); $db->orderBy("id","asc");
...@@ -479,11 +492,6 @@ if (!$db->ping()) ...@@ -479,11 +492,6 @@ if (!$db->ping())
$db->connect() $db->connect()
``` ```
Obtain an initialized instance of the class from another class
```php
$db = MysqliDb::getInstance();
```
Get last executed SQL query. Get last executed SQL query.
Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables. Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables.
```php ```php
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment