@@ -7,7 +7,7 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
77** [ Update Query] ( #update-query ) **
88** [ Select Query] ( #select-query ) **
99** [ Delete Query] ( #delete-query ) **
10- ** [ Generic Query ] ( #generic-query-method ) **
10+ ** [ Running raw SQL queries ] ( #running-raw-sql-queries ) **
1111** [ Query Keywords] ( #query-keywords ) **
1212** [ Raw Query] ( #raw-query-method ) **
1313** [ Where Conditions] ( #where-method ) **
@@ -53,21 +53,35 @@ $db = new MysqliDb (Array (
5353 'password' => 'password',
5454 'db'=> 'databaseName',
5555 'port' => 3306,
56+ 'prefix' => 'my_',
5657 'charset' => 'utf8'));
5758```
58- port and charset params are optional.
59+ prefix, port and charset params are optional.
5960
6061Reuse already connected mysqli:
6162``` php
6263$mysqli = new mysqli ('host', 'username', 'password', 'databaseName');
6364$db = new MysqliDb ($mysqli);
6465```
6566
66- Its also possible to set a table prefix:
67+ Its also possible to set a table prefix via separate call :
6768``` php
6869$db->setPrefix ('my_');
6970```
7071
72+ If you need to get already created mysqliDb object from another class or function use
73+ ``` php
74+ function init () {
75+ // db staying private here
76+ $db = new MysqliDb ('host', 'username', 'password', 'databaseName');
77+ }
78+ function myfunc () {
79+ // obtain db object created in init ()
80+ $db = MysqliDb::getInstance();
81+ ...
82+ }
83+ ```
84+
7185Next, prepare your data, and call the necessary methods.
7286
7387### Objects mapping
110124```
111125
112126### Replace Query
113- replace() method implements same API as insert();
127+ < a href = ' https://dev.mysql.com/doc/refman/5.0/en/ replace.html ' >Replace()</ a > method implements same API as insert();
114128
115129### Update Query
116130``` php
@@ -176,21 +190,13 @@ echo $u->login;
176190// Json return type
177191$json = $db->JsonBuilder()->getOne("users");
178192```
179- ### Delete Query
180- ``` php
181- $db->where('id', 1);
182- if($db->delete('users')) echo 'successfully deleted';
183- ```
184-
185- ### Generic Query Method
186- By default rawQuery() will filter out special characters so if you getting problems with it
187- you might try to disable filtering function. In this case make sure that all external variables are passed to the query via bind variables
188193
194+ ### Running raw SQL queries
189195``` php
190196// filtering enabled
191197$users = $db->rawQuery('SELECT * from users where customerId=?', Array (10));
192198// filtering disabled
193- //$users = $db->rawQuery('SELECT * from users where id >= ?', Array (10), false );
199+ //$users = $db->rawQuery('SELECT * from users where id >= ?', Array (10));
194200foreach ($users as $user) {
195201 print_r ($user);
196202}
@@ -336,6 +342,13 @@ $results = $db
336342 ->get('users');
337343```
338344
345+ ### Delete Query
346+ ``` php
347+ $db->where('id', 1);
348+ if($db->delete('users')) echo 'successfully deleted';
349+ ```
350+
351+
339352### Ordering method
340353``` php
341354$db->orderBy("id","asc");
@@ -479,11 +492,6 @@ if (!$db->ping())
479492 $db->connect()
480493```
481494
482- Obtain an initialized instance of the class from another class
483- ``` php
484- $db = MysqliDb::getInstance();
485- ```
486-
487495Get last executed SQL query.
488496Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables.
489497``` php
0 commit comments