本文整理汇总了PHP中R::getRedBean方法的典型用法代码示例。如果您正苦于以下问题:PHP R::getRedBean方法的具体用法?PHP R::getRedBean怎么用?PHP R::getRedBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::getRedBean方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _log_focus
function _log_focus($openid, $operation, $user_info = NULL)
{
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
$user = R::getRedBean()->dispense('wxcsc_focus');
$user->openid = $openid;
$user->operation = $operation;
if ($operation == 'focus' && $user_info != NULL) {
$user->nickname = $user_info['nickname'];
$user->sex = $user_info['sex'];
$user->language = $user_info['language'];
$user->city = $user_info['city'];
$user->province = $user_info['province'];
$user->country = $user_info['country'];
}
$user_id = R::store($user);
} 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();
}
示例2: save_notice_log
function save_notice_log($notice_id, $type, $target, $contents)
{
$send_id = -1;
_log(json_encode(['notice_id' => $notice_id, 'type' => $type, 'target' => $target, 'contents' => $contents]));
R::selectDatabase('kayako');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
$send_log = R::getRedBean()->dispense('esr_ticket_notification_log');
$send_log->notice_id = $notice_id;
$send_log->notice_type = $type;
$send_log->notice_target = $target;
$send_log->contents = $contents;
$send_id = R::store($send_log);
} catch (Exception $e) {
die(json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]));
}
R::close();
return $send_id;
}
示例3: json_encode
$relate_6->zhanshileixing = 0;
$relate_6->guanlianname = '客户用电较上月浮动最大Top5';
$relate_6->yidongmiaoshu = json_encode($top5, JSON_UNESCAPED_UNICODE);
$relate_6->guanlianzhi = $run_time;
if (R::store($relate_6) <= 0) {
exit('DB relate_6 insert failed \\n');
}
}
} catch (Exception $e) {
exit('DB relate_6 insert failed \\n' . $e->getMessage());
}
R::close();
/* 写入运行日志 */
R::addDatabase('config', $GLOBALS['db_config_url'], $GLOBALS['db_config_user'], $GLOBALS['db_config_pass']);
R::selectDatabase('config');
if (!R::testConnection()) {
exit('DB config connect failed \\n' . $e->getMessage());
}
R::freeze(TRUE);
try {
$run_log = R::getRedBean()->dispense('sys_run_log');
$run_log->alarm_type = $run_type;
$run_log->last_run = $run_time;
if (R::store($run_log) <= 0) {
exit('DB config insert failed \\n');
}
} catch (Exception $e) {
exit('DB config insert failed \\n' . $e->getMessage());
}
R::close();
die('Run ' . $run_type . ' at ' . $run_time . ' done');
示例4: header
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'missing argument']);
die;
}
// Save
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
$prefer_exists = R::find('wxcsc_notice_prefer', 'username = :username AND stage = :stage', [':username' => $username, ':stage' => $stage]);
$prefer_exists = array_filter($prefer_exists);
if (empty($prefer_exists)) {
$prefer_new = R::getRedBean()->dispense('wxcsc_notice_prefer');
$prefer_new->username = $username;
$prefer_new->stage = $stage;
$prefer_new->wechat = $method == 'wechat' ? $prefer == 'on' ? 1 : 0 : 0;
$prefer_new->email = $method == 'email' ? $prefer == 'on' ? 1 : 0 : 0;
$prefer_new->mobile = $method == 'mobile' ? $prefer == 'on' ? 1 : 0 : 0;
$prefer_new_id = R::store($prefer_new);
} else {
$prefer_exist = array_shift($prefer_exists);
if ($method == 'wechat') {
$prefer_exist->wechat = $prefer == 'on' ? 1 : 0;
}
if ($method == 'email') {
$prefer_exist->email = $prefer == 'on' ? 1 : 0;
}
if ($method == 'mobile') {
示例5: exit
die;
}
R::close();
// Save frequent people
R::addDatabase('supportsr', $GLOBALS['db_supportsr_url'], $GLOBALS['db_supportsr_user'], $GLOBALS['db_supportsr_pass']);
R::selectDatabase('supportsr');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
R::begin();
foreach ($people_array as $people) {
$person_old = R::getCell(' SELECT id ' . ' FROM supportsr.esr_frequent_people ' . ' WHERE name = :name ' . ' AND paper_number = :p_number ', [':name' => $people->pname, ':p_number' => $people->pidval]);
if (empty($person_old) || $person_old == "") {
$person_new = R::getRedBean()->dispense('esr_frequent_people');
$person_new->name = $people->pname;
$person_new->paper_type = $people->ptype == '身份证' ? '身份证/Id card' : ($people->ptype == '台胞证' ? '台胞证/Efficiency certificate' : ($people->ptype == '护照' ? '护照/Passport' : ($people->ptype == '港澳通行证' ? '港澳通行证/Hong Kong-Macau passport' : ($people->ptype == '驾驶证' ? '驾驶证/Driving license' : ''))));
$person_new->paper_number = $people->pidval;
$person_new->comid = $user['organizationname'] . '|*|' . $user['userorganizationid'];
$person_new_id = R::store($person_new);
}
}
R::commit();
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]);
R::rollback();
die;
}
R::close();
示例6: ldap_close
ldap_close($ldap_conn);
die;
}
ldap_close($ldap_conn);
// Save
R::addDatabase('wechat_pe', $GLOBALS['db_wechat_pe_url'], $GLOBALS['db_wechat_pe_user'], $GLOBALS['db_wechat_pe_pass']);
R::selectDatabase('wechat_pe');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
$user_exists = R::find('wxpe_users', 'openid = :openid', [':openid' => $user_openid]);
$user_exists = array_filter($user_exists);
if (empty($user_exists)) {
$user_new = R::getRedBean()->dispense('wxpe_users');
$user_new->openid = $user_openid;
$user_new->phone = '';
$user_new->email = $user_name;
$user_new->extra = $user_pass;
$user_new_id = R::store($user_new);
} else {
$user_exist = array_shift($user_exists);
$user_exist->email = $user_name;
R::store($user_exist);
}
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
die;
}
示例7: _log
_log(json_encode(['user_name' => $user_name, 'spitslot' => $spitslot_str]));
// Check
if (empty($user_name) || empty($spitslot_str)) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'missing argument']);
die;
}
// Insert
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
// Insert
try {
$spitslot = R::getRedBean()->dispense('wxcsc_spitslot');
$spitslot->username = $user_name;
$spitslot->spitslot = rawurldecode($spitslot_str);
$spitslot->approved = 0;
$spitslot_id = R::store($spitslot);
} 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();
// Return
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true']);
die;
示例8: explode
$answers = explode(';', $answer_str);
if (empty($answers) || count($answers) == 0) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'invalid post data']);
die;
}
// Insert
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
// Insert
try {
$surveys = R::getRedBean()->dispense('wxcsc_survey', count($answers));
for ($i = 0; $i < count($answers); $i++) {
list($q, $a) = explode(':', $answers[$i]);
$surveys[$i]->survey_id = $survey_id;
$surveys[$i]->username = $user_name;
$surveys[$i]->question_id = $q;
$surveys[$i]->answer = $a;
}
$ids = R::storeAll($surveys);
} 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();
// Return
示例9: exit
}
R::freeze(TRUE);
try {
$run_log = R::getRedBean()->dispense('sys_run_log');
$run_log->alarm_type = $run_type;
$run_log->last_run = $run_time;
if (R::store($run_log) <= 0) {
exit('DB config insert 1 failed \\n');
}
} catch (Exception $e) {
exit('DB config insert failed \\n' . $e->getMessage());
}
/* 写入:最后读取到的事件编号 */
try {
if (count($event_lvl1n2) > 0) {
$last_event = end($event_lvl1n2);
$key_id = $last_event['key_id'];
$last_id = R::getRedBean()->dispense('sys_last_id');
$last_id->alarm_type = $run_type;
$last_id->key_name = 'Incident_Number';
$last_id->key_val = $key_id;
$last_id->create_time = $run_time;
if (R::store($last_id) <= 0) {
exit('DB config insert 2 failed \\n');
}
}
} catch (Exception $e) {
exit('DB config insert failed \\n' . $e->getMessage());
}
R::close();
die('Run ' . $run_type . ' at ' . $run_time . ' done');
示例10: _setExtendedFunctionsDB
protected function _setExtendedFunctionsDB()
{
R::ext('xdispense', function ($type) {
return R::getRedBean()->dispense($type);
});
}
示例11: _log
_log(json_encode(['user_name' => $user_name, 'reason' => $reason, 'complain' => $complain_text]));
// Check
if (empty($user_name) || empty($reason)) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'missing argument']);
die;
}
// Insert
R::addDatabase('wechat_pe', $GLOBALS['db_wechat_pe_url'], $GLOBALS['db_wechat_pe_user'], $GLOBALS['db_wechat_pe_pass']);
R::selectDatabase('wechat_pe');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
// Insert
try {
$complain = R::getRedBean()->dispense('wxpe_complain');
$complain->username = $user_name;
$complain->reason = $reason;
$complain->complain = $complain_text;
$complain_id = R::store($complain);
} 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();
// Return
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true']);
die;
示例12: print_r
<?php
require 'rb.php';
/* 设置连接属性 数据库类型 数据库名 用户名密码等 */
R::setup('mysql:host=localhost;dbname=dbname', 'dbusername', 'dbpassword');
/* native SQL query */
$book = R::getAll('SELECT * FROM tbl_user');
echo "<pre>";
print_r($book);
/* ORM save */
/* 注意这里不要使用前缀下划线命名的表 否则会抛出错误 如tbl_user */
$usertb = R::dispense("usertb");
$usertb->name = 'aaas';
$usertb->age = 200;
R::store($usertb);
/* ORM save */
/* 下面的方法可用于在下划线的表 */
define('PAGE', 'tbl_user');
R::ext('xdispense', function ($type) {
return R::getRedBean()->dispense($type);
});
$tbl_user = R::xdispense(PAGE);
$tbl_user->name = 'aaas';
$tbl_user->age = 200;
R::store($tbl_user);
示例13: 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();
//.........这里部分代码省略.........
示例14: exit
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);
// Query
try {
$user_id = R::getcell(' SELECT su.userid' . ' FROM swusers su' . ' INNER JOIN swuseremails sm' . ' ON su.userid = sm.linktypeid' . ' AND sm.linktype = 1' . ' WHERE sm.email = :email', [':email' => $user_name]);
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]);
die;
}
try {
$rating = R::getRedBean()->dispense('esr_workorder_assignee_rating');
$rating->workorder_id = $workorder_id;
$rating->workorder_assignee = $staff_id_or_name;
$rating->rating_creator = $user_id;
$rating->rating_result = $score;
$rating_id = R::store($rating);
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error kayako', 'details' => $e->getMessage()]);
die;
}
R::close();
// Return
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true']);
die;