->query()

->query() – Envoie une requête

Synopsis

void $DB_DataObject->query ( string $string )

Description

Envoie une requête à la base de données. Vous devriez penser que l'utilisation de plusieurs appels aux méthodes whereAdd et orderBy n'est pas forcément nécessaire, et qu'il est plus simple d'écrire simplement la requête, question de rendre le code plus propre et plus court.

Parameter

  • string $string - Requête SQL

Note

This function can not be called statically.

Example

Requêtes sur une base de données

<?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)
Libère les ressources (Next)
Last updated: Sun, 29 Aug 2010 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

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