Skip to content

HowTo: DBDriver for querying

DevAlien edited this page Feb 3, 2011 · 1 revision

DBDriver for querying

Function to use

public function query($query, $type = self::QUERY, $parameters = array(), $limit = array(), $cache = false)

$query ⇒ The written query but for each parameter except the LIMIT you must use a ? (QUESTION MARK)

$type ⇒ Type of the query

  • DBDriver::QUERY ⇒ To execute a normal query without a result

  • DBDriver::ALIST ⇒ To get a list, usefull for the loops in the Template Engine EXAMPLE(Table with 2 fields (field1, field2) and will extract 2 rows

Array
(
    [0] => Array
        (
            [field1] => value1
            [field2] => value2
        )

    [1] => Array
        (
            [field1] => value1
            [field2] => value2
        )

)
  • DBDriver::AARRAY ⇒ To get an array, just one row

Array
        (
            [field1] => value1
            [field2] => value2
        )

)
  • DBDriver::COUNT ⇒ Will return the number of the rows that the query returned

  • DBDriver::LASTID ⇒ In an INSERT you will get the id insert (on the autoincrement field)

$parameter ⇒ array with the parameters (array('hello'))

$limit ⇒ array with the limit ( array(1) OR array(1, 10) )

$cache ⇒ true or false if you want cache

-

-

EXAMPLE Final result: SELECT * FROM ANE_dev_users where name like '%te%' AND status = 1 LIMIT 1, 10

$db->query('SELECT * FROM '.$database['tbl_prefix'].'dev_users where name like ? AND status = ?', DBDriver::ALIST, array('%te%', 1), array(1, 10));

OR

$db->query('SELECT * FROM '.$database['tbl_prefix'].'dev_users where name like ? AND status = ?', DBDriver::ALIST, array('%'.$nametosearch.'%', $status), array(1, 10));
Clone this wiki locally