->query() – send a raw query


void $DB_DataObject->query ( string $string )


Sends a raw query to database. Often you may consider that using a large number of whereAdd's and orderBy method calls are not necessary, and it would be simpler to just write the query, to make the code clearer and shorter.


  • string $string - SQL Query


This function can not be called statically.


raw queries on the database

= new DataObjects_Person;
$person->query("SELECT * FROM {$person->__table} WHERE id > 12 ORDER BY id");
while (
$person->fetch()) {
Advanced Filters - ::
query(), ::
SelectAdd(), ::
whereAdd(), ::
Limit(), ::
OrderBy(), ::
GroupBy(), (Previous)
Free resources (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

Note by: didier.galland@gmail.com
"LIMIT" instruction is ignored if present in the query string passed to query(). You must set explicitly your limit by $dataObject->limit(0,5)

I suppose it's a bug, not a feature.

//this won't work as expected
$dataObject->query('SELECT * FROM my_table LIMIT 0,5');//10000 records in my_table

$res[]=$dataObject->name;//loops of 10 000 iterations

To obtain only 5 results, you must write :
$dataObject->query('SELECT * FROM my_table');//10000 records in my_table
Note by: delatbabel@spamgourmet.com
Undocumented features in query:

->query('BEGIN'); causes a begin transaction
->query('COMMIT'); causes a commit
->query('ROLLBACK'); causes a rollback

... for databases that support it.