本文整理汇总了PHP中DatabaseConnection::ConnectionFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::ConnectionFactory方法的具体用法?PHP DatabaseConnection::ConnectionFactory怎么用?PHP DatabaseConnection::ConnectionFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::ConnectionFactory方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
* Connects to the database server. If no arguments are
* supplied, then the connection is attempted for the
* database authentication variables in config.php.
*
* @param (optional) connection_string a PDO connection string
* @param (optional) db_user the database user name
* @param (optional) db_pass the database user password
* @return bool
*/
public static function connect()
{
/*
if connection has been instantiated (ie: not null), check if is already connected
*/
if (null != DB::instance()->connection) {
if (func_num_args() == 0 && false != DB::instance()->connection->is_connected()) {
return true;
}
}
if (func_num_args() > 0) {
$connect_string = func_get_arg(0);
$db_user = func_get_arg(1);
$db_pass = func_get_arg(2);
} else {
/* We use the config.php variables */
$connect_string = Config::get('db_connection')->connection_string;
$db_user = Config::get('db_connection')->username;
$db_pass = Config::get('db_connection')->password;
}
DB::instance()->connection = DatabaseConnection::ConnectionFactory($connect_string);
if (null != DB::instance()->connection) {
return DB::instance()->connection->connect($connect_string, $db_user, $db_pass);
} else {
// do some error handling here. The connect string does not have a corresponding DB connection object
print _t('Panic! No database connection class appears to be found for the connection string specified. Please check config.php');
}
}
示例2: action_handler_dev_feed
public function action_handler_dev_feed($handler_vars)
{
$rss = Plugins::get_by_interface('RSS');
if (count($rss) !== 1) {
exit;
}
$xml = reset($rss)->create_rss_wrapper();
$connection_string = Options::get('tracfeed__connection_string');
$username = Options::get('tracfeed__username');
$password = Options::get('tracfeed__password');
$db = DatabaseConnection::ConnectionFactory($connection_string);
$db->connect($connection_string, $username, $password);
$times = $db->get_column('SELECT time from ticket_change group by time order by time desc limit 15;');
$mintime = array_reduce($times, 'min', reset($times));
$comments = $db->get_results("\n\t\t\tSELECT *, ticket_change.time as changetime from ticket_change \n\t\t\tINNER JOIN ticket on ticket.id = ticket_change.ticket\n\t\t\twhere \n\t\t\tchangetime >= ? and\n\t\t\tnot (field ='comment' and newvalue = '') \n\t\t\torder by ticket_change.time DESC;\n\t\t", array($mintime));
$posts = array();
foreach ($comments as $comment) {
$post_id = md5($comment->ticket . ':' . $comment->changetime . ':' . $comment->author);
if (!array_key_exists($post_id, $posts)) {
$post = new Post();
$post->title = "Ticket #{$comment->ticket}: {$comment->summary}";
$post->content = "Changes by {$comment->author} on ticket <a href=\"http://trac.habariproject.org/habari/ticket/{$comment->ticket}\">#{$comment->ticket}</a>.\n<br>\n<br>";
$post->guid = 'tag:' . Site::get_url('hostname') . ',trac_comment,' . $post_id;
$post->content_type = 'dev_feed';
$post->slug = "http://trac.habariproject.org/habari/ticket/{$comment->ticket}";
$post->pubdate = date('r', $comment->changetime);
$posts[$post_id] = $post;
} else {
$post = $posts[$post_id];
}
switch ($comment->field) {
case 'comment':
$content = $comment->newvalue;
$content = preg_replace('/\\b(https?|ftp|file):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|]/i', '<a href="$0">[link]</a>', $content);
$content = preg_replace('%\\br([0-9]+)\\b%', '<a href="http://trac.habariproject.org/habari/changeset/$1">r$1</a>', $content);
$content = preg_replace('%\\b#([0-9]+)\\b%', '<a href="http://trac.habariproject.org/habari/ticket/$1">$1</a>', $content);
$post->content .= "Comment #{$comment->oldvalue} by {$comment->author}:\n<blockquote><pre>{$content}</pre></blockquote>\n<br>";
break;
default:
if (trim($comment->oldvalue) == '') {
$post->content .= "Set <b>{$comment->field}</b> to: {$comment->newvalue}\n<br>";
} else {
$post->content .= "Changed <b>{$comment->field}</b> from: {$comment->oldvalue}\n<br> To: {$comment->newvalue}\n<br>";
}
break;
}
}
$xml = RSS::add_posts($xml, $posts);
ob_clean();
header('Content-Type: application/xml');
echo $xml->asXML();
exit;
}
示例3: wp_connect
/**
* Attempt to connect to the WordPress database
*
* @param string $db_host The hostname of the WP database
* @param string $db_name The name of the WP database
* @param string $db_user The user of the WP database
* @param string $db_pass The user's password for the WP database
* @param string $db_prefix The table prefix for the WP instance in the database
* @return mixed false on failure, DatabseConnection on success
*/
private function wp_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix)
{
// Connect to the database or return false
try {
$wpdb = DatabaseConnection::ConnectionFactory("mysql:host={$db_host};dbname={$db_name}");
$wpdb->connect("mysql:host={$db_host};dbname={$db_name}", $db_user, $db_pass);
return $wpdb;
} catch (Exception $e) {
return false;
}
}
示例4: wp_connect
private function wp_connect($db_host, $db_name, $db_user, $db_pass)
{
// build the connection string, since we stupidly have to use it twice
$connection_string = 'mysql:host=' . $db_host . ';dbname=' . $db_name;
try {
$wpdb = DatabaseConnection::ConnectionFactory($connection_string);
$wpdb->connect($connection_string, $db_user, $db_pass);
// @todo make sure preifx_* tables exist?
return $wpdb;
} catch (Exception $e) {
// just hide connection errors, it's enough that we errored out
return false;
}
}
示例5: chryp_connect
/**
* Attempt to connect to the Chyrp database
*
* @param string $connect_string The connection string of the Habari database
* @param string $db_user The user of the database
* @param string $db_pass The user's password for the database
* @return mixed false on failure, DatabseConnection on success
*/
private function chryp_connect($connect_string, $db_user, $db_pass)
{
// Connect to the database or return false
try {
$db = DatabaseConnection::ConnectionFactory($connect_string);
$db->connect($connect_string, $db_user, $db_pass);
return $db;
} catch (Exception $e) {
return false;
}
}