当前位置: 首页>>代码示例>>PHP>>正文


PHP Facade::findOrDispense方法代码示例

本文整理汇总了PHP中RedBeanPHP\Facade::findOrDispense方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::findOrDispense方法的具体用法?PHP Facade::findOrDispense怎么用?PHP Facade::findOrDispense使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedBeanPHP\Facade的用法示例。


在下文中一共展示了Facade::findOrDispense方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPDOParameterBinding

 /**
  * Test parameter binding with\PDO.
  * 
  * @return void
  */
 public function testPDOParameterBinding()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     R::getDatabaseAdapter()->getDatabase()->setUseStringOnlyBinding(TRUE);
     try {
         R::getAll("select * from job limit ? ", array(1));
         fail();
     } catch (\Exception $e) {
         pass();
     }
     try {
         R::getAll("select * from job limit :l ", array(":l" => 1));
         fail();
     } catch (\Exception $e) {
         pass();
     }
     try {
         R::exec("select * from job limit ? ", array(1));
         fail();
     } catch (\Exception $e) {
         pass();
     }
     try {
         R::exec("select * from job limit :l ", array(":l" => 1));
         fail();
     } catch (\Exception $e) {
         pass();
     }
     R::getDatabaseAdapter()->getDatabase()->setUseStringOnlyBinding(FALSE);
     try {
         R::getAll("select * from job limit ? ", array(1));
         pass();
     } catch (\Exception $e) {
         print_r($e);
         fail();
     }
     try {
         R::getAll("select * from job limit :l ", array(":l" => 1));
         pass();
     } catch (\Exception $e) {
         fail();
     }
     try {
         R::exec("select * from job limit ? ", array(1));
         pass();
     } catch (\Exception $e) {
         fail();
     }
     try {
         R::exec("select * from job limit :l ", array(":l" => 1));
         pass();
     } catch (\Exception $e) {
         fail();
     }
     testpack("Test findOrDispense");
     $person = R::findOrDispense("person", " job = ? ", array("developer"));
     asrt(count($person) > 0, TRUE);
     $person = R::findOrDispense("person", " job = ? ", array("musician"));
     asrt(count($person) > 0, TRUE);
     $musician = array_pop($person);
     asrt(intval($musician->id), 0);
     try {
         $adapter->exec("an invalid query");
         fail();
     } catch (SQL $e) {
         pass();
     }
     asrt((int) $adapter->getCell("SELECT 123"), 123);
     asrt((int) $adapter->getCell("SELECT ?", array("987")), 987);
     asrt((int) $adapter->getCell("SELECT ?+?", array("987", "2")), 989);
     asrt((int) $adapter->getCell("SELECT :numberOne+:numberTwo", array(":numberOne" => 42, ":numberTwo" => 50)), 92);
     $pair = $adapter->getAssoc("SELECT 'thekey','thevalue' ");
     asrt(is_array($pair), TRUE);
     asrt(count($pair), 1);
     asrt(isset($pair["thekey"]), TRUE);
     asrt($pair["thekey"], "thevalue");
     testpack('Test whether we can properly bind and receive NULL values');
     asrt($adapter->getCell('SELECT :nil ', array(':nil' => 'NULL')), 'NULL');
     asrt($adapter->getCell('SELECT :nil ', array(':nil' => NULL)), NULL);
     asrt($adapter->getCell('SELECT ? ', array('NULL')), 'NULL');
     asrt($adapter->getCell('SELECT ? ', array(NULL)), NULL);
 }
开发者ID:skullyframework,项目名称:skully,代码行数:91,代码来源:Parambind.php

示例2: testFinding

 /**
  * Begin testing.
  * This method runs the actual test pack.
  *
  * @return void
  */
 public function testFinding()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new AssociationManager($toolbox);
     $page = $redbean->dispense("page");
     $page->name = "John's page";
     $idpage = $redbean->store($page);
     $page2 = $redbean->dispense("page");
     $page2->name = "John's second page";
     $idpage2 = $redbean->store($page2);
     $a->associate($page, $page2);
     $pageOne = $redbean->dispense("page");
     $pageOne->name = "one";
     $pageMore = $redbean->dispense("page");
     $pageMore->name = "more";
     $pageEvenMore = $redbean->dispense("page");
     $pageEvenMore->name = "evenmore";
     $pageOther = $redbean->dispense("page");
     $pageOther->name = "othermore";
     set1toNAssoc($a, $pageOther, $pageMore);
     set1toNAssoc($a, $pageOne, $pageMore);
     set1toNAssoc($a, $pageOne, $pageEvenMore);
     asrt(count($redbean->find("page", array(), " name LIKE '%more%' ", array())), 3);
     asrt(count($redbean->find("page", array(), " name LIKE :str ", array(":str" => '%more%'))), 3);
     asrt(count($redbean->find("page", array(), array(" name LIKE :str ", array(":str" => '%more%')))), 3);
     asrt(count($redbean->find("page", array(), " name LIKE :str ", array(":str" => '%mxore%'))), 0);
     asrt(count($redbean->find("page", array("id" => array(2, 3)))), 2);
     $bean = $redbean->dispense("wine");
     $bean->name = "bla";
     for ($i = 0; $i < 10; $i++) {
         $redbean->store($bean);
     }
     $redbean->find("wine", array("id" => 5));
     //  Finder:where call OODB::convertToBeans
     $bean2 = $redbean->load("anotherbean", 5);
     asrt($bean2->id, 0);
     $keys = $adapter->getCol("SELECT id FROM page WHERE " . $writer->esc('name') . " LIKE '%John%'");
     asrt(count($keys), 2);
     $pages = $redbean->batch("page", $keys);
     asrt(count($pages), 2);
     $p = R::findLast('page');
     pass();
     $row = R::getRow('select * from page ');
     asrt(is_array($row), TRUE);
     asrt(isset($row['name']), TRUE);
     // Test findAll -- should not throw an exception
     asrt(count(R::findAll('page')) > 0, TRUE);
     asrt(count(R::findAll('page', ' ORDER BY id ')) > 0, TRUE);
     $beans = R::findOrDispense("page");
     asrt(count($beans), 6);
     asrt(is_null(R::findLast('nothing')), TRUE);
     try {
         R::find('bean', ' id > 0 ', 'invalid bindings argument');
         fail();
     } catch (RedException $exception) {
         pass();
     }
 }
开发者ID:cesium147,项目名称:redbean,代码行数:68,代码来源:Finding.php


注:本文中的RedBeanPHP\Facade::findOrDispense方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。