Commit 2dab030a authored by Alexander Butenko's avatar Alexander Butenko

documentation adjustments

parent 0763046c
...@@ -35,17 +35,12 @@ composer require joshcam/mysqli-database-class:dev-master ...@@ -35,17 +35,12 @@ composer require joshcam/mysqli-database-class:dev-master
``` ```
### Initialization ### Initialization
Simple initialization with utf8 charset by default: Simple initialization with utf8 charset set by default:
```php ```php
$db = new MysqliDb ('host', 'username', 'password', 'databaseName'); $db = new MysqliDb ('host', 'username', 'password', 'databaseName');
``` ```
Or in case usage of the namespaces:
```php
$db = new \MysqliDb ('host', 'username', 'password', 'databaseName');
```
Advanced initialization:
Advanced initialization. If no charset should be set charset, set it to null
```php ```php
$db = new MysqliDb (Array ( $db = new MysqliDb (Array (
'host' => 'host', 'host' => 'host',
...@@ -56,15 +51,16 @@ $db = new MysqliDb (Array ( ...@@ -56,15 +51,16 @@ $db = new MysqliDb (Array (
'prefix' => 'my_', 'prefix' => 'my_',
'charset' => 'utf8')); 'charset' => 'utf8'));
``` ```
prefix, port and charset params are optional. table prefix, port and database charset params are optional.
If no charset should be set charset, set it to null
Reuse already connected mysqli: Also it is possible to reuse already connected mysqli object:
```php ```php
$mysqli = new mysqli ('host', 'username', 'password', 'databaseName'); $mysqli = new mysqli ('host', 'username', 'password', 'databaseName');
$db = new MysqliDb ($mysqli); $db = new MysqliDb ($mysqli);
``` ```
Its also possible to set a table prefix via separate call: If no table prefix were set during object creation its possible to set it later with a separate call:
```php ```php
$db->setPrefix ('my_'); $db->setPrefix ('my_');
``` ```
...@@ -75,6 +71,7 @@ If you need to get already created mysqliDb object from another class or functio ...@@ -75,6 +71,7 @@ If you need to get already created mysqliDb object from another class or functio
// db staying private here // db staying private here
$db = new MysqliDb ('host', 'username', 'password', 'databaseName'); $db = new MysqliDb ('host', 'username', 'password', 'databaseName');
} }
...
function myfunc () { function myfunc () {
// obtain db object created in init () // obtain db object created in init ()
$db = MysqliDb::getInstance(); $db = MysqliDb::getInstance();
...@@ -82,10 +79,8 @@ If you need to get already created mysqliDb object from another class or functio ...@@ -82,10 +79,8 @@ If you need to get already created mysqliDb object from another class or functio
} }
``` ```
Next, prepare your data, and call the necessary methods.
### Objects mapping ### Objects mapping
dbObject.php is an object mapping library built on top of mysqliDb to provide model prepresentation functionality. dbObject.php is an object mapping library built on top of mysqliDb to provide model representation functionality.
See <a href='dbObject.md'>dbObject manual for more information</a> See <a href='dbObject.md'>dbObject manual for more information</a>
### Insert Query ### Insert Query
...@@ -156,9 +151,9 @@ if ($db->update ('users', $data)) ...@@ -156,9 +151,9 @@ if ($db->update ('users', $data))
else else
echo 'update failed: ' . $db->getLastError(); echo 'update failed: ' . $db->getLastError();
``` ```
### Select Query ### Select Query
After any select/get function calls amount or returned rows After any select/get function calls amount or returned rows is stored in $count variable
is stored in $count variable
```php ```php
$users = $db->get('users'); //contains an Array of all users $users = $db->get('users'); //contains an Array of all users
$users = $db->get('users', 10); //contains an Array 10 users $users = $db->get('users', 10); //contains an Array 10 users
...@@ -234,7 +229,6 @@ $resutls = $db->rawQuery ($q, $params); ...@@ -234,7 +229,6 @@ $resutls = $db->rawQuery ($q, $params);
print_r ($results); // contains Array of returned rows print_r ($results); // contains Array of returned rows
``` ```
### Where Method ### Where Method
This method allows you to specify where parameters of the query. This method allows you to specify where parameters of the query.
......
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