本文整理汇总了PHP中ORM::getLastQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::getLastQuery方法的具体用法?PHP ORM::getLastQuery怎么用?PHP ORM::getLastQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ORM
的用法示例。
在下文中一共展示了ORM::getLastQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMemcaching
public function testMemcaching()
{
ORM::configure('caching', true);
ORM::configure('caching_driver', 'memcache');
ORM::addMemcacheServer(array('host' => '127.0.0.1', 'port' => '11211'));
ORM::forTable('widget')->where('name', 'Fred')->where('age', 17)->findOne();
ORM::forTable('widget')->where('name', 'Bob')->where('age', 42)->findOne();
$expected = ORM::getLastQuery();
// this shouldn't run a query!
ORM::forTable('widget')->where('name', 'Fred')->where('age', 17)->findOne();
$this->assertEquals($expected, ORM::getLastQuery());
Orm::clearCache();
// this should run now.
ORM::forTable('widget')->where('name', 'Fred')->where('age', 17)->findOne();
$this->assertEquals("SELECT * FROM `widget` WHERE `name` = 'Fred' AND `age` = '17' LIMIT 1", Orm::getLastQuery());
}
示例2: testComplexRelationships
public function testComplexRelationships()
{
$book = Model::factory('Book')->findOne(1);
$authors = $book->authors()->findMany();
$expected = "SELECT `author`.* FROM `author` JOIN `author_book` ON `author`.`id` = `author_book`.`author_id` WHERE `author_book`.`book_id` = '1'";
$this->assertEquals($expected, ORM::getLastQuery());
$book2 = Model::factory('BookTwo')->findOne(1);
$authors2 = $book2->authors()->findMany();
$expected = "SELECT `author_two`.* FROM `author_two` JOIN `wrote_the_book` ON `author_two`.`id` = `wrote_the_book`.`custom_author_id` WHERE `wrote_the_book`.`custom_book_id` = '1'";
$this->assertEquals($expected, ORM::getLastQuery());
$this->assertEquals($expected, ORM::getLastQuery());
}