// SELECT * FROM users where agentId = 10 or agentId = 20
```
### Subqueries
Subquery in selects:
```php
$ids=$db->subQuery();
$ids->where("qty",2,">");
$ids->get("products",null,"userId");
$db->where("id",$ids,'in');
$res=$db->get("users");
// Gives SELECT * FROM users WHERE id IN (SELECT userId FROM products WHERE qty > 2)
```
Subquery in inserts:
```php
$userIdQ=$db->subQuery();
$userIdQ->where("id",6);
$userIdQ->getOne("users","name"),
$data=Array(
"productName"=>"test product",
"userId"=>$userIdQ,
"lastUpdated"=>$db->now()
);
$id=$db->insert("products",$data);
// Gives INSERT INTO PRODUCTS (productName, userId, lastUpdated) values ("test product", (SELECT name FROM users WHERE id = 6), NOW());
```
### Helper commands
### Helper commands
Reconnect in case mysql connection died
Reconnect in case mysql connection died
```php
```php
...
@@ -227,3 +271,25 @@ Obtain an initialized instance of the class from another class
...
@@ -227,3 +271,25 @@ Obtain an initialized instance of the class from another class
```php
```php
$db=MysqliDb::getInstance();
$db=MysqliDb::getInstance();
```
```
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.
```php
$db->get('users');
echo"Last executed query was ".$db->getLastQuery();
```
### Transaction helpers
Please keep in mind that transactions are working on innoDB tables.