->query()

->query() – 生のクエリを送出する

Synopsis

void $DB_DataObject->query ( string $string )

Description

データベースに生のクエリを送出します。 しばしば、 大量の whereAdd や orderBy メソッドコールは必要でないと考えるかも知れません。 これは、ただクエリを書くだけよりも単純で、 コードをクリーンにかつ簡潔にします。

Parameter

  • string $string - SQL クエリを指定します。

Note

This function can not be called statically.

Example

データベースでの生のクエリ

<?php
$person 
= new DataObjects_Person;
$person->query("SELECT * FROM {$person->__table} WHERE id > 12 ORDER BY id");
while (
$person->fetch()) {
  echo 
$person->name;
}
?>
高度なフィルタ - ::
query(), ::
SelectAdd(), ::
whereAdd(), ::
Limit(), ::
OrderBy(), ::
GroupBy(), (Previous)
リソースを解放する (Next)
Last updated: Wed, 23 Apr 2014 — 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