or select with custom columns set. Functions also could be used
or select with custom columns set. Functions also could be used
```php
```php
$stats=$db->getOne("users","sum(id), count(*) as cnt");
$cols=Array("id","name","email");
echo"total ".$stats['cnt']."users found";
$cols=Array("id, name, email");
$users=$db->get("users",null,$cols);
$users=$db->get("users",null,$cols);
if($db->count>0)
if($db->count>0)
foreach($usersas$user){
foreach($usersas$user){
...
@@ -92,6 +109,9 @@ or select just one row
...
@@ -92,6 +109,9 @@ or select just one row
$db->where("id",1);
$db->where("id",1);
$user=$db->getOne("users");
$user=$db->getOne("users");
echo$user['id'];
echo$user['id'];
$stats=$db->getOne("users","sum(id), count(*) as cnt");
echo"total ".$stats['cnt']."users found";
```
```
### Delete Query
### Delete Query
...
@@ -122,28 +142,38 @@ print_r($results); // contains Array of returned rows
...
@@ -122,28 +142,38 @@ print_r($results); // contains Array of returned rows
### Where Method
### Where Method
This method allows you to specify the parameters of the query.
This method allows you to specify where parameters of the query.
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.
Regular == operator:
Regular == operator with variables:
```php
```php
$db->where('id',1);
$db->where('id',1);
$db->where('login','admin');
$db->where('login','admin');
$results=$db->get('users');
$results=$db->get('users');
// Gives: SELECT * FROM users WHERE id=1 AND login='admin';
// Gives: SELECT * FROM users WHERE id=1 AND login='admin';
```
```
Regular == operator with column to column comparison:
```php
```php
$db->where('id',50,">=");
// WRONG
// or $db->where('id', Array('>=' => 50));
$db->where('lastLogin','createdAt');
// CORRECT
$db->where('lastLogin = createdAt');
$results=$db->get('users');
// Gives: SELECT * FROM users WHERE lastLogin = createdAt;
```
$results=$db->get('users');
```php
$db->where('id',50,">=");
// or $db->where ('id', Array ('>=' => 50));
$results=$db->get('users');
// Gives: SELECT * FROM users WHERE id >= 50;
// Gives: SELECT * FROM users WHERE id >= 50;
```
```
BETWEEN / NOT BETWEEN:
BETWEEN / NOT BETWEEN:
```php
```php
$db->where('id',Array(4,20),'between');
$db->where('id',Array(4,20),'BETWEEN');
// or $db->where('id', Array('between' => Array(4, 20) ) );
// or $db->where ('id', Array ('BETWEEN' => Array(4, 20)));
$results=$db->get('users');
$results=$db->get('users');
// Gives: SELECT * FROM users WHERE id BETWEEN 4 AND 20
// Gives: SELECT * FROM users WHERE id BETWEEN 4 AND 20