$db->select('* from users');
$db->select('* from users')->where(['username'=>'Felix']);
where() should only be chained once on the select() operator in the predefined order.
$db->select('* from users')->where(['username'=>'Felix']);
$result = $db->read();
read() method is
capable of applying limits to queries. Another method results() can be used to
obtain and remodify data obtained from the database. Let's take a look at some few examples.
$db->query('select * from users')->read(1);
$db->query('select * from users')->read(1, 2);
$db->query('select * from users')->read(5, 7);
$db->query('select * from users where username = ?',['Felix']);
$result1 = $db->read()? $db->results() : [];
$result2 = $db->read()? $db->results(0) : [];
$result3 = $db->read()? $db->results(0, 'username') : [];
$result1 obtained above translates [0 => ['username'=>Felix]],
$result2 translates that the zero 0 key should be fetched, hence : $result2 will translate as ['username'=>Felix] $result3 will translate as Felix $result2 or $result3 will be set as an empty value.
$db->query('select * from users where username = ?',['Felix'])->read(50);
$six_results = $db->results(':6');
$ten_results = $db->results(':10');
$six_results will only pull 6 results out of 50 results obtained or
less depending on the total number of results obtained. The second result obtained above i.e
$ten_results will only pull 10 results out of 50 results obtained or
less depending on the total number of results obtained.
$db->query('select * from users where username = ?',['Felix'])->read(50);
$results1 = $db->results(':shuffle');
$results2 = $db->results(':10', ':shuffle');
$results2 above, 10 data was pulled out of 50 data and then reshuffled.
Notice the shift in position of :shuffle directive when two arguments are supplied.