->query()

->query() – send a raw query

Synopsis

void $DB_DataObject->query ( string $string )

Description

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.

Parameter

  • string $string - SQL Query

Note

This function can not be called statically.

Example

raw queries on the database

<?php
$person 
= new DataObjects_Person;
$person->query("SELECT * FROM {$person->__table} WHERE id > 12 ORDER BY id");
while (
$person->fetch()) {
  echo 
$person->name;
}
?>
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

$n=$dataObject->find();//$n==10000
while($dataObject->fetch()){
$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
$dataObject->limit(0,5);
$n=$dataObject->find();//$n==5
...
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.

Del