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


PHP R::getAssoc方法代码示例

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


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

示例1: testVaria

 /**
  * Various tests for OCI.
  * 
  * @return void
  */
 public function testVaria()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $page = $redbean->dispense("page");
     try {
         $adapter->exec("an invalid query");
         fail();
     } catch (RedBean_Exception_SQL $e) {
         pass();
     }
     asrt((int) $adapter->getCell("SELECT 123 FROM DUAL"), 123);
     $page->aname = "my page";
     $id = (int) $redbean->store($page);
     asrt((int) $page->id, 1);
     asrt((int) $pdo->GetCell("SELECT count(*) FROM page"), 1);
     asrt($pdo->GetCell("SELECT aname FROM page WHERE ROWNUM<=1"), "my page");
     asrt((int) $id, 1);
     $page = $redbean->load("page", 1);
     asrt($page->aname, "my page");
     asrt((bool) $page->getMeta("type"), TRUE);
     asrt(isset($page->id), TRUE);
     asrt($page->getMeta("type"), "page");
     asrt((int) $page->id, $id);
     R::nuke();
     $rooms = R::dispense('room', 2);
     $rooms[0]->kind = 'suite';
     $rooms[1]->kind = 'classic';
     $rooms[0]->number = 6;
     $rooms[1]->number = 7;
     R::store($rooms[0]);
     R::store($rooms[1]);
     $rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM room ORDER BY kind ASC');
     foreach ($rooms as $key => $room) {
         asrt($key === 6 || $key === 7, TRUE);
         asrt($room == 'classic' || $room == 'suite', TRUE);
     }
     $rooms = R::$adapter->getAssoc('SELECT kind FROM room');
     foreach ($rooms as $key => $room) {
         asrt($room == 'classic' || $room == 'suite', TRUE);
         asrt($room, $key);
     }
     $rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM rooms2 ORDER BY kind ASC');
     asrt(count($rooms), 0);
     asrt(is_array($rooms), TRUE);
     $date = R::dispense('mydate');
     $date->date = '2012-12-12 20:50';
     $date->time = '12:15';
     $id = R::store($date);
     $ok = R::load('mydate', 1);
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:59,代码来源:Database.php

示例2: exit

    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user_email = R::getCell('SELECT email' . '  FROM wxcsc_users' . ' WHERE openid = :openid' . ' LIMIT 1', [':openid' => $user_openid]);
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
    die;
}
R::close();
_log(json_encode(['openid' => $user_openid, 'user_email' => $user_email]));
// Query
R::addDatabase('kayako', $GLOBALS['db_kayako_url'], $GLOBALS['db_kayako_user'], $GLOBALS['db_kayako_pass']);
R::selectDatabase('kayako');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user = R::getRow('     SELECT a.fullname AS name, ' . '            c.organizationname AS organization,' . '            a.phone AS phone,' . '            b.email AS email,' . '            d.com_century AS dc_id' . '       FROM kayako_fusion.swusers a' . ' INNER JOIN kayako_fusion.swuseremails b ' . '         ON a.userid = b.linktypeid' . ' INNER JOIN kayako_fusion.swuserorganizations c' . '         ON a.userorganizationid = c.userorganizationid' . '  LEFT JOIN supportsr.order_service_company d' . '         ON d.com_id = c.userorganizationid' . '      WHERE b.email = :email' . '        AND b.linktype = 1', [':email' => $user_email]);
    $user_dc_id_arr = explode(',', $user['dc_id']);
    $user_dc = R::getAssoc('SELECT name' . '  FROM supportsr.esr_companylist' . ' WHERE id IN (' . R::genSlots($user_dc_id_arr) . ')', $user_dc_id_arr);
} catch (Exception $e) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]);
    die;
}
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true', 'user' => $user, 'user_dc' => $user_dc], JSON_UNESCAPED_UNICODE);
die;
开发者ID:adexbn,项目名称:gds_wechat,代码行数:31,代码来源:user_info.php

示例3: testSelects

 /**
  * Test selecting.
  * 
  * @return void
  */
 public function testSelects()
 {
     $rooms = R::dispense('room', 2);
     $rooms[0]->kind = 'suite';
     $rooms[1]->kind = 'classic';
     $rooms[0]->number = 6;
     $rooms[1]->number = 7;
     R::store($rooms[0]);
     R::store($rooms[1]);
     $rooms = R::getAssoc('SELECT * FROM room WHERE id < -999');
     asrt(is_array($rooms), TRUE);
     asrt(count($rooms), 0);
     $rooms = R::getAssoc('SELECT ' . R::$writer->esc('number') . ', kind FROM room ORDER BY kind ASC');
     foreach ($rooms as $key => $room) {
         asrt($key === 6 || $key === 7, TRUE);
         asrt($room == 'classic' || $room == 'suite', TRUE);
     }
     $rooms = R::$adapter->getAssoc('SELECT kind FROM room');
     foreach ($rooms as $key => $room) {
         asrt($room == 'classic' || $room == 'suite', TRUE);
         asrt($room, $key);
     }
     $rooms = R::getAssoc('SELECT `number`, kind FROM rooms2 ORDER BY kind ASC');
     asrt(count($rooms), 0);
     asrt(is_array($rooms), TRUE);
     // GetCell should return NULL in case of exception
     asrt(NULL, R::getCell('SELECT dream FROM fantasy'));
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:33,代码来源:Database.php

示例4: testBeautifulColumnNames

 /**
  * Test beautification of column names.
  * 
  * @return void
  */
 public function testBeautifulColumnNames()
 {
     testpack('Beautiful column names');
     $town = R::dispense('town');
     $town->isCapital = FALSE;
     $town->hasTrainStation = TRUE;
     $town->name = 'BeautyVille';
     $houses = R::dispense('house', 2);
     $houses[0]->isForSale = TRUE;
     $town->ownHouse = $houses;
     R::store($town);
     $town = R::load('town', $town->id);
     asrt($town->isCapital == FALSE, TRUE);
     asrt($town->hasTrainStation == TRUE, TRUE);
     asrt($town->name == 'BeautyVille', TRUE);
     testpack('Accept datetime objects.');
     $cal = R::dispense('calendar');
     $cal->when = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
     asrt($cal->when, '2000-01-01 00:00:00');
     testpack('Affected rows test');
     $currentDriver = $this->currentlyActiveDriverID;
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $bean = $redbean->dispense('bean');
     $bean->prop = 3;
     //make test run with strict mode as well
     $redbean->store($bean);
     $adapter->exec('UPDATE bean SET prop = 2');
     asrt($adapter->getAffectedRows(), 1);
     testpack('Testing Logger');
     R::$adapter->getDatabase()->setLogger(new RedBean_Logger_Default());
     asrt(R::$adapter->getDatabase()->getLogger() instanceof RedBean_Logger, TRUE);
     asrt(R::$adapter->getDatabase()->getLogger() instanceof RedBean_Logger_Default, TRUE);
     $bean = R::dispense('bean');
     $bean->property = 1;
     $bean->unsetAll(array('property'));
     asrt($bean->property, NULL);
     asrt($bean->setAttr('property', 2) instanceof RedBean_OODBBean, TRUE);
     asrt($bean->property, 2);
     asrt(preg_match('/\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d/', R::isoDate()), 1);
     asrt(preg_match('/\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d/', R::isoDateTime()), 1);
     $redbean = R::getRedBean();
     $adapter = R::getDatabaseAdapter();
     $writer = R::getWriter();
     asrt($redbean instanceof RedBean_OODB, TRUE);
     asrt($adapter instanceof RedBean_Adapter, TRUE);
     asrt($writer instanceof RedBean_QueryWriter, TRUE);
     R::setRedBean($redbean);
     pass();
     //cant really test this
     R::setDatabaseAdapter($adapter);
     pass();
     //cant really test this
     R::setWriter($writer);
     pass();
     //cant really test this
     $u1 = R::dispense('user');
     $u1->name = 'Gabor';
     $u1->login = 'g';
     $u2 = R::dispense('user');
     $u2->name = 'Eric';
     $u2->login = 'e';
     R::store($u1);
     R::store($u2);
     $list = R::getAssoc('select login,' . R::$writer->esc('name') . ' from ' . R::$writer->esc('user') . ' ');
     asrt($list['e'], 'Eric');
     asrt($list['g'], 'Gabor');
     $painting = R::dispense('painting');
     $painting->name = 'Nighthawks';
     $id = R::store($painting);
     testpack('Testing Plugin Cooker');
     $cooker = new RedBean_Plugin_Cooker();
     $cooker->setToolbox($toolbox);
     try {
         asrt($cooker->graph('abc'), 'abc');
         fail();
     } catch (RedBean_Exception_Security $e) {
         pass();
     }
     testpack('Testing SQL Error Types');
     foreach ($writer->typeno_sqltype as $code => $text) {
         asrt(is_integer($code), TRUE);
         asrt(is_string($text), TRUE);
     }
     foreach ($writer->sqltype_typeno as $text => $code) {
         asrt(is_integer($code), TRUE);
         asrt(is_string($text), TRUE);
     }
     testpack('Testing Nowhere Pt. 1 (unfrozen)');
     foreach (array('exec', 'getAll', 'getCell', 'getAssoc', 'getRow', 'getCol') as $method) {
         R::$method('select * from nowhere');
         pass();
//.........这里部分代码省略.........
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:101,代码来源:Misc.php


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