You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+18-17Lines changed: 18 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ MysqliDb -- Simple MySQLi wrapper and object mapper with prepared statements
10
10
**[Select Query](#select-query)**
11
11
**[Delete Query](#delete-query)**
12
12
**[Insert Data](#insert-data)**
13
-
**[Insert XML](#insert-xml)**
14
-
**[Pagination](#pagination)**
13
+
**[Insert XML](#insert-xml)**
14
+
**[Pagination](#pagination)**
15
15
**[Running raw SQL queries](#running-raw-sql-queries)**
16
16
**[Query Keywords](#query-keywords)**
17
17
**[Where Conditions](#where--having-methods)**
@@ -375,7 +375,7 @@ Array
375
375
MysqliDb can return result in 3 different formats: Array of Array, Array of Objects and a Json string. To select a return type use ArrayBuilder(), ObjectBuilder() and JsonBuilder() methods. Note that ArrayBuilder() is a default return type
376
376
```php
377
377
// Array return type
378
-
$= $db->getOne("users");
378
+
$u= $db->getOne("users");
379
379
echo $u['login'];
380
380
// Object return type
381
381
$u = $db->ObjectBuilder()->getOne("users");
@@ -395,21 +395,21 @@ To avoid long if checks there are couple helper functions to work with raw query
395
395
396
396
Get 1 row of results:
397
397
```php
398
-
$user = $db->rawQueryOne ('select * from users where id=?', Array(10));
398
+
$user = $db->rawQueryOne('SELECT * from users where id=?', Array(10));
399
399
echo $user['login'];
400
400
// Object return type
401
-
$user = $db->ObjectBuilder()->rawQueryOne ('select * from users where id=?', Array(10));
401
+
$user = $db->ObjectBuilder()->rawQueryOne('SELECT * from users where id=?', Array(10));
402
402
echo $user->login;
403
403
```
404
404
Get 1 column value as a string:
405
405
```php
406
-
$password = $db->rawQueryValue ('select password from users where id=? limit 1', Array(10));
406
+
$password = $db->rawQueryValue('SELECT password from users where id=? limit 1', Array(10));
407
407
echo "Password is {$password}";
408
408
NOTE: for a rawQueryValue() to return string instead of an array 'limit 1' should be added to the end of the query.
409
409
```
410
410
Get 1 column value from multiple rows:
411
411
```php
412
-
$logins = $db->rawQueryValue ('select login from users limit 10');
412
+
$logins = $db->rawQueryValue('SELECT login from users limit 10');
413
413
foreach ($logins as $login)
414
414
echo $login;
415
415
```
@@ -438,7 +438,7 @@ print_r ($results); // contains Array of returned rows
438
438
### Where / Having Methods
439
439
`where()`, `orWhere()`, `having()` and `orHaving()` methods allows you to specify where and having conditions of the query. All conditions supported by where() are supported by having() as well.
440
440
441
-
WARNING: In order to use column to column comparisons only raw where conditions should be used as column name or functions cant be passed as a bind variable.
441
+
WARNING: In order to use column to column comparisons only raw where conditions should be used as column name or functions cannot be passed as a bind variable.
442
442
443
443
Regular == operator with variables:
444
444
```php
@@ -523,7 +523,7 @@ $results = $db->get("users");
523
523
Or raw condition with variables:
524
524
```php
525
525
$db->where ("(id = ? or id = ?)", Array(6,2));
526
-
$db->where ("login","mike")
526
+
$db->where ("login","mike");
527
527
$res = $db->get ("users");
528
528
// Gives: SELECT * FROM users WHERE (id = 6 or id = 2) and login='mike';
// SELECT * FROM customers where agentId = 10 and active = 1 limit 10, 10
654
+
// SELECT * FROM customers WHERE agentId = 10 AND active = 1 LIMIT 10, 10
654
655
655
656
$cnt = $db->getValue ("customers", "count(id)");
656
657
echo "total records found: " . $cnt;
657
-
// SELECT count(id) FROM users where agentId = 10 and active = 1
658
+
// SELECT count(id) FROM customers WHERE agentId = 10 AND active = 1
658
659
```
659
660
660
661
### Subqueries
@@ -713,11 +714,11 @@ print_r ($products);
713
714
### EXISTS / NOT EXISTS condition
714
715
```php
715
716
$sub = $db->subQuery();
716
-
$sub->where("company", 'testCompany');
717
-
$sub->get ("users", null, 'userId');
717
+
$sub->where("company", 'testCompany');
718
+
$sub->get ("users", null, 'userId');
718
719
$db->where (null, $sub, 'exists');
719
720
$products = $db->get ("products");
720
-
// Gives SELECT * FROM products WHERE EXISTS (select userId from users where company='testCompany')
721
+
// Gives SELECT * FROM products WHERE EXISTS (SELECT userId FROM users WHERE company='testCompany')
721
722
```
722
723
723
724
### Has method
@@ -744,7 +745,7 @@ if (!$db->ping())
744
745
```
745
746
746
747
Get last executed SQL query:
747
-
Please note that function returns SQL query only for debugging purposes as its execution most likely will fail due missing quotes around char variables.
748
+
Please note that this method returns the SQL query only for debugging purposes as its execution most likely will fail due to missing quotes around char variables.
748
749
```php
749
750
$db->get('users');
750
751
echo "Last executed query was ". $db->getLastQuery();
0 commit comments