本文整理汇总了PHP中R::addDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP R::addDatabase方法的具体用法?PHP R::addDatabase怎么用?PHP R::addDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::addDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: add_writer_to_tests
/**
* Convenience function for test hook.
* If you added the proper Writer class, the facade should be able
* to automatically load it, i.e. \RedBeanPHP\QueryWriter\MyWriter
*
* @global array $ini
*
* @param string $name name of the connection (key)
* @param string $dsn DSN to connect
* @param string $user username
* @param string $pass passwords
*/
function add_writer_to_tests($name, $dsn, $user, $pass)
{
global $ini;
\RedUNIT\Base::addToDriverList($name);
R::addDatabase($name, $dsn, $user, $pass);
$ini[$name] = true;
}
示例3: loadDatabase
public static function loadDatabase($dbFile)
{
$path = strpos($dbFile, DIRECTORY_SEPARATOR) === false ? Config::$dbPath . DIRECTORY_SEPARATOR . $dbFile : $dbFile;
$dsn = 'sqlite:' . $path;
$key = basename($path);
R::addDatabase($key, $dsn, null, null, true);
R::selectDatabase($key);
R::exec('PRAGMA foreign_keys=ON');
R::exec('PRAGMA temp_store=MEMORY');
}
示例4: joomla
public static function joomla($prefix, $facade = null)
{
$app = JFactory::getApplication();
if ($app->getCfg('dbtype') == 'mysqli') {
$type = 'mysql';
} else {
$type = $app->getCfg('dbtype');
}
if (is_null($facade)) {
R::addDatabase('joomla', $type . ':' . 'host=' . $app->getCfg('host') . ';' . 'dbname=' . $app->getCfg('db'), $app->getCfg('user'), $app->getCfg('password'));
R::selectDatabase('joomla');
R::prefix($prefix);
} else {
$facade::addDatabase('joomla', $type . ':' . 'host=' . $app->getCfg('host') . ';' . 'dbname=' . $app->getCfg('db'), $app->getCfg('user'), $app->getCfg('password'));
$facade::selectDatabase('joomla');
$facade::prefix($prefix, $facade);
}
}
示例5: __construct
function __construct()
{
// Include database configuration
include APPPATH . 'config/database.php';
// Get Redbean
include APPPATH . 'third_party/vendor/rb/rb.php';
$this->config = $db;
$this->default = $active_group;
foreach ($this->config as $name => $group) {
// Database data
$host = $group['hostname'];
$user = $group['username'];
$pass = $group['password'];
$dbname = $group['database'];
// Setup DB connection
R::addDatabase($name, "pgsql:host={$host};dbname={$dbname}", $user, $pass);
}
$this->select($this->default);
}
示例6: exit
if (!$ldap_conn) {
exit('Ldap bind failed');
}
$user_dn = 'cn=' . $user_name . ',ou=people,dc=gds-services,dc=com';
ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
$ldap_bd = ldap_bind($ldap_conn, $user_dn, $user_pass);
if (!$ldap_bd) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'invalid user']);
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);
示例7: get_notice_prefer_dcs_csc
function get_notice_prefer_dcs_csc($inner_name, $p_stage)
{
$prefer_wechat = false;
$prefer_email = false;
$prefer_mobile = false;
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);
$email_prefix = explode("@", $inner_name);
try {
$notice_prefer = R::getRow('SELECT wechat, ' . ' email, ' . ' mobile ' . ' FROM wxpe_notice_prefer ' . ' WHERE ( username = :username_1 ' . ' OR username = :username_2 ) ' . ' AND stage = :stage ', [':username_1' => $email_prefix[0], ':username_2' => ucfirst($email_prefix[0]), ':stage' => $p_stage]);
if (!empty($notice_prefer)) {
$prefer_wechat = $notice_prefer['wechat'];
$prefer_email = $notice_prefer['email'];
$prefer_mobile = $notice_prefer['mobile'];
} else {
_log('Notice prefer of dcs csc [' . $email_prefix[0] . '] @ [' . $p_stage . '] not configed...');
}
} catch (Exception $e) {
die(json_encode(['result' => 'failed', 'error' => 'db error wechat_pe', 'details' => $e->getMessage()]));
}
R::close();
if (TEST_SEND) {
$prefer_wechat = true;
$prefer_email = true;
$prefer_mobile = true;
}
return array($prefer_wechat, $prefer_email, $prefer_mobile);
}
示例8: json_encode
$relate_6 = R::getRedBean()->dispense('dcom_yidongguanlian');
$relate_6->yidong_code = $run_type . $run_time . '-' . $dc_id;
$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());
}
示例9: trim
<?php
require "config.php";
require "external/rb.php";
R::setup('mysql:host=' . $dbserver . ';dbname=' . $dbname, $dbuser, $dbpassword);
R::freeze(TRUE);
R::debug(TRUE, 2);
R::addDatabase('localdb', 'mysql:host=' . $dbserver . ';dbname=' . $dbname, $dbuser, $dbpassword, TRUE);
R::begin();
require 'actions-web.php';
if (isset($_COOKIE["loguserid"])) {
$userid = $_COOKIE["loguserid"];
} else {
$userid = 0;
}
if (isset($_COOKIE["logsession"])) {
$session = $_COOKIE["logsession"];
}
$action = "";
if (isset($_GET["action"])) {
$action = trim($_GET["action"]);
}
switch ($action) {
case "smscode":
$number = trim($_GET["number"]);
smscode($number);
break;
case "register":
$number = trim($_GET["validatednumber"]);
$smscode = trim($_GET["smscode"]);
$checkcode = trim($_GET["checkcode"]);
示例10: exit
R::addDatabase('portal', $GLOBALS['db_portal_url'], $GLOBALS['db_portal_user'], $GLOBALS['db_portal_pass']);
R::selectDatabase('portal');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
$staff_skills = R::getRow(' SELECT s2.name AS staff_name,' . ' IFNULL(dict.text, "-") AS job_title,' . ' IFNULL(s2.img_url, "") AS staff_photo,' . ' IFNULL(GROUP_CONCAT(",", k.name), "-") AS skill_name,' . ' 0 AS rate_score,' . ' 0 AS experience_count' . ' FROM portal.p_stuff s2' . ' LEFT JOIN p_dict_info dict' . ' ON dict.value = s2.station' . ' AND dict.dict_name = "PEOPLE_STATION"' . ' LEFT JOIN portal.p_stuff_skill_r r' . ' ON s2.id = r.stuff_id' . ' LEFT JOIN portal.p_skill k' . ' ON r.skill_id = k.id' . ' WHERE s2.name = :staff_name' . ' GROUP BY s2.name,' . ' s2.station,' . ' s2.img_url' . ' LIMIT 1', [':staff_name' => $staff_id_or_name]);
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]);
die;
}
R::close();
// Query rating and experience count
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 {
$staff_rate_score = R::getCell(' SELECT AVG(rating_result) AS rate_score' . ' FROM supportsr.esr_workorder_assignee_rating r' . ' WHERE r.workorder_assignee = :workorder_assignee' . ' GROUP BY r.workorder_assignee', [':workorder_assignee' => $staff_id_or_name]);
_log(json_encode(['staff_rate_score' => $staff_rate_score]));
} catch (Exception $e) {
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]);
die;
}
if (empty($staff_rate_score) || $staff_rate_score == NULL) {
$staff_rate_score = 4.0;
示例11: testpack
<?php
/**
* Pretest
*
* These tests will run before the configuration takes place
* in the unit test suite (mostly error handling tests).
*
* @file RedUNIT/Pretest.php
* @desc Test scripts that run before configuration
* @author Gabor de Mooij and the RedBeanPHP Community
* @license New BSD/GPLv2
*
* (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
* This source file is subject to the New BSD/GPLv2 License that is bundled
* with this source code in the file license.txt.
*/
testpack('Running pre-tests. (before config).');
try {
R::debug(TRUE);
fail();
} catch (Exception $e) {
pass();
}
asrt(R::testConnection(), FALSE);
R::addDatabase('broken', 'mysql:host=nowhere', 'defunct', 'void');
R::selectDatabase('broken');
asrt(R::testConnection(), FALSE);
示例12: get_dcs_contact
function get_dcs_contact($dcs_name)
{
$dcs_email = '';
$dcs_phone = '';
// portal
R::addDatabase('portal', $GLOBALS['db_portal_url'], $GLOBALS['db_portal_user'], $GLOBALS['db_portal_pass']);
R::selectDatabase('portal');
if (!R::testConnection()) {
exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
$dcs = R::getRow('SELECT email, ' . ' cell_phone ' . ' FROM gdsportal.auth_user ' . ' WHERE name = :name ', [':name' => $dcs_name]);
$dcs_email = $dcs['email'];
$dcs_phone = $dcs['cell_phone'];
} catch (Exception $e) {
die(json_encode(['result' => 'failed', 'error' => 'db error portal', 'details' => $e->getMessage()]));
}
R::close();
return array($dcs_email, $dcs_phone);
}
示例13: array_pop
$abook = array_pop($books["can"]);
asrt("red", $abook->cover);
$books = $r2->cooker($form2);
$abook = array_pop($books["can"]);
asrt("green", $abook->cover);
$r1->associate($book, $page1);
$r2->associate($book2, $page2);
$r1->view("shelf", "book,page");
$a = $r1->getAll("select * from shelf where id = {$id1} ");
$shelf = array_pop($a);
asrt($shelf["title_of_page"], "FIRST");
$r2->view("shelf", "book,page");
$shelf = $r2->getCell("select title_of_page from shelf where id = {$id2} ");
asrt($shelf, "SECOND");
R::addDatabase("D1", "sqlite:/tmp/database_1.txt", "");
R::addDatabase("D2", "sqlite:/tmp/database_2.txt", "");
R::selectDatabase("D1");
R::wipe('bottle');
foreach (R::dispense('bottle', 5) as $bottle) {
R::store($bottle);
}
R::selectDatabase("D2");
R::wipe('bottle');
foreach (R::dispense('bottle', 3) as $bottle) {
R::store($bottle);
}
R::selectDatabase("D1");
asrt(intval(R::getCell('select count(*) from bottle')), 5);
R::selectDatabase("D2");
asrt(intval(R::getCell('select count(*) from bottle')), 3);
asrt(count(R::findAndExport('bottle')), 3);
示例14: RedBeanConnect
/**
*
* @param string $dbname
* @param boolean $frozen
* @return void
*/
protected static function RedBeanConnect($dbname, $frozen = true)
{
require_once implode(DIRECTORY_SEPARATOR, [ROOT_DIR, 'Library', 'database', 'rb.php']);
$dbConfig = static::$dbConfig;
switch (strtoupper($dbConfig->type)) {
case 'SQLITE':
$dns = "sqlite:/tmp/{$dbname}.sqlite3";
$dbConfig->user = $dbConfig->password = null;
break;
case 'MARIA':
$dns = "mysql:host={$dbConfig->host};dbname={$dbname}";
break;
case 'POSTGRESQL':
$dns = "pgsql:host={$dbConfig->host};dbname={$dbname}";
break;
case null:
default:
$dns = null;
$dbConfig->user = $dbConfig->password = null;
}
if (isset(R::$toolboxes[$dbname])) {
R::selectDatabase($dbname);
} else {
R::addDatabase($dbname, $dns, $dbConfig->user, $dbConfig->password, $frozen);
R::selectDatabase($dbname);
}
R::setAutoResolve();
R::fancyDebug(DEBUG);
}
示例15: array
$hookPath = '';
$colorMap = array('mysql' => '0;31', 'pgsql' => '0;32', 'sqlite' => '0;34');
@(include 'cli/test_hook.php');
//Configure the databases
if (isset($ini['mysql'])) {
$dsn = "mysql:host={$ini['mysql']['host']};dbname={$ini['mysql']['schema']}";
R::addDatabase('mysql', $dsn, $ini['mysql']['user'], $ini['mysql']['pass'], FALSE);
R::selectDatabase('mysql');
R::exec(' SET GLOBAL sql_mode="" ');
}
if (isset($ini['pgsql'])) {
$dsn = "pgsql:host={$ini['pgsql']['host']};dbname={$ini['pgsql']['schema']}";
R::addDatabase('pgsql', $dsn, $ini['pgsql']['user'], $ini['pgsql']['pass'], FALSE);
}
if (isset($ini['sqlite'])) {
R::addDatabase('sqlite', 'sqlite:' . $ini['sqlite']['file'], NULL, NULL, FALSE);
}
R::selectDatabase('sqlite');
// Function to activate a driver
function activate_driver($d)
{
R::selectDatabase($d);
}
$arguments = $_SERVER['argc'];
$mode = 'all';
if ($arguments > 1) {
$mode = $_SERVER['argv'][1];
}
$classSpec = null;
if ($arguments > 2) {
$classSpec = $_SERVER['argv'][2];