本文整理汇总了PHP中JO_Db::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP JO_Db::factory方法的具体用法?PHP JO_Db::factory怎么用?PHP JO_Db::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JO_Db
的用法示例。
在下文中一共展示了JO_Db::factory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createConnection
/**
* Create an instance of JO_Db_Adapter_Abstract.
*
* @param array $server master (supplier) or slave (consumer)
* @return JO_Db_Adapter_Abstract|false
* @see JO_Db
*/
public function createConnection($server)
{
$config = $this->getConfig();
foreach ($config as $key => $value) {
if ('servers' !== $key && !array_key_exists($key, $server)) {
$server[$key] = $value;
}
}
$db = JO_Db::factory($config['adapter'], $server);
if ($this->isConnected($db)) {
return $db;
}
return false;
}
示例2: indexAction
public function indexAction()
{
$request = $this->getRequest();
$this->view->msg_error = array();
$this->view->msg_success = array();
//begin updater
$sys_config = APPLICATION_PATH . '/config/config_db.ini';
if (!file_exists($sys_config)) {
$this->view->msg_error['old_sys'] = 'System Db config file not found: <strong>' . $sys_config . '</strong>';
} elseif (!is_writable($sys_config)) {
$this->view->msg_error['old_sys'] = '<strong>' . $sys_config . '</strong> must be writable!';
}
$upload_folder = BASE_PATH . '/uploads/';
if (!is_writable($upload_folder)) {
$this->view->msg_error['upload'] = '<strong>' . $upload_folder . '</strong> must be writable!';
}
$upload_folder = BASE_PATH . '/cache/';
if (!is_writable($upload_folder)) {
$this->view->msg_error['cache'] = '<strong>' . $upload_folder . '</strong> must be writable!';
}
if (!$this->view->msg_error && $request->getPost('install') == 'yes') {
$db_params = $request->getPost('params');
$db_params['charset'] = 'utf8';
foreach ($db_params as $key => $value) {
if (!$value && in_array($key, array('password', 'dbname'))) {
$db_params[$key] = ' ';
}
}
$error = false;
try {
$db = JO_Db::factory("MYSQLi", $db_params);
$db->query("ALTER DATABASE `" . $request->getPost('params[dbname]') . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
$db->query("SET NAMES 'utf8'");
} catch (JO_Db_Exception $e) {
$error = $e->getMessage();
}
if ($db->isConnected()) {
if (trim($request->getPost('username')) == '') {
$this->view->msg_error['username'] = 'You must type your username';
} elseif (!preg_match('/^[a-zA-Z0-9_]+$/i', $request->getPost('username'))) {
$this->view->msg_error['username'] = 'The username you have entered is not valid';
}
if (trim($request->getPost('password')) == '') {
$this->view->msg_error['password'] = 'You must type your password';
}
if (trim($request->getPost('admin_mail')) == '') {
$this->view->msg_error['admin_mail'] = 'You must type your email';
} elseif (!self::ValidMail($request->getPost('admin_mail'))) {
$this->view->msg_error['admin_mail'] = 'You must type valid email';
}
if (trim($request->getPost('report_mail')) == '') {
$this->view->msg_error['report_mail'] = 'You must type your email';
} elseif (!self::ValidMail($request->getPost('report_mail'))) {
$this->view->msg_error['report_mail'] = 'You must type valid email';
}
if (count($this->view->msg_error) == 0) {
if ($request->getPost('demo') == 'yes') {
$result = Model_Install::installWithDemo($db);
} else {
$result = Model_Install::installWithoutDemo($db);
}
if ($result) {
JO_Action::getInstance()->redirect($request->getBaseUrl() . '?module=install&action=success');
} else {
$this->view->msg_error['install_error'] = 'An error occurred during installation. Try again to install and the installation fails, contact <a target="_blank" title="marketplace script" href="http://cloneforest.com"> Marketplace script </a>';
}
}
} else {
$this->view->msg_error['db_connect'] = $error;
}
}
}
示例3: setDb
/**
* Set Db configuration settings
*
* @param array $options
* @return JO_Db
*/
public function setDb($options)
{
$adapter = null;
if (!isset($options['adapter'])) {
throw new JO_Exception("Db adapter not set");
} elseif (empty($options['adapter'])) {
throw new JO_Exception("Db adapter is empty");
}
if (!isset($options['params']) || !is_array($options['params'])) {
throw new JO_Exception("Db params error");
}
$this->_db = JO_Db_Table::setDefaultAdapter(JO_Db::factory($options['adapter'], $options['params']));
return $this->_db;
}