本文整理汇总了PHP中ConnectionManager::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager::getInstance方法的具体用法?PHP ConnectionManager::getInstance怎么用?PHP ConnectionManager::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnection
/**
* Get current connection
*
* @return \Doctrine\DBAL\Driver\Connection|\Doctrine\DBAL\Connection|\Blast\Orm\Connection
*/
public function getConnection()
{
if (null === $this->connection) {
$this->connection = ConnectionManager::getInstance()->get();
}
return $this->connection;
}
示例2: main
function main()
{
$this->Auth = new AuthComponent(null);
$this->out('Migracion de base de datos RFIETP');
$this->hr();
$this->out('Introduzca la version a la que desea migrar (por ej: 1.7 o "q" para salir):');
$user_version = trim($this->in(''));
if ($user_version != 'q') {
$this->out('Chequeando version de base de datos...');
$db = ConnectionManager::getInstance();
$conn = $db->getDataSource('default');
$res = $conn->query('SELECT * FROM version ORDER BY id DESC;');
$current_version = $res[0][0]['version'];
$this->out($current_version);
if (version_compare($user_version, $current_version) == 1) {
// actualiza version => ejecuta script en BD
if (file_exists(sprintf(NOMBRE_ARCHIVO, $user_version))) {
// ejecuta script sql
$sql = file_get_contents(sprintf(NOMBRE_ARCHIVO, $user_version), true);
$conn->query($sql);
// actualiza version de BD
$conn->query("INSERT INTO version (version, fecha) VALUES ('" . $user_version . "', NOW())");
$this->out("La base de datos se ha actualizado a la version " . $user_version);
} else {
$this->out("El archivo " . sprintf(NOMBRE_ARCHIVO, $user_version) . " no existe. Proceso abortado!");
}
} else {
$this->out("");
$this->out("La versión actual " . $current_version . " es mayor que " . $user_version);
}
}
$this->out("");
$this->hr();
}
示例3: prepare
/**
* Prepare "environment" for invocation on bean method. Configures
* the PropertyManager (always), the Logger (if log.ini has been provided
* with the bean) and ConnectionManager (if database.ini has been provided
* with the bean).
*
*/
protected function prepare()
{
if ($this->configuration['log.ini']) {
Logger::getInstance()->configure(Properties::fromString($this->configuration['cl']->getResource('etc/log.ini')));
}
if ($this->configuration['database.ini']) {
ConnectionManager::getInstance()->configure(Properties::fromString($this->configuration['cl']->getResource('etc/database.ini')));
}
}
示例4: instanceWith
/**
* Returns an instance with a given number of DSNs
*
* @param [:string] dsns
* @return rdbms.ConnectionManager
*/
protected function instanceWith($dsns)
{
$properties = '';
foreach ($dsns as $name => $dsn) {
$properties .= '[' . $name . "]\ndsn=\"" . $dsn . "\"\n";
}
$cm = ConnectionManager::getInstance();
$cm->configure(Properties::fromString($properties));
return $cm;
}
示例5: _preflight_check
function _preflight_check()
{
App::import('Model', 'ConnectionManager');
$errorMessage = "\nYou need to create an entry for your joomla " . "database in croogo's configuration file.\n";
$connectionManager = ConnectionManager::getInstance();
if (!property_exists($connectionManager->config, 'joomla')) {
$this->out($errorMessage);
exit;
}
}
示例6: instanceWith
/**
* Returns an instance with a given number of DSNs
*
* @param [:string] dsns
* @return rdbms.ConnectionManager
*/
protected function instanceWith($dsns)
{
$cm = ConnectionManager::getInstance();
foreach ($dsns as $name => $dsn) {
if (FALSE !== ($p = strpos($name, '.'))) {
$cm->queue($dsn, substr($name, 0, $p), substr($name, $p + 1));
} else {
$cm->queue($dsn, $name);
}
}
return $cm;
}
示例7: __construct
/**
* Constructor.
*
* @return void
* @access private
*/
function __construct($id = false, $table = null, $ds = null, $tablePrefix = null)
{
if ($tablePrefix) {
$cm =& ConnectionManager::getInstance();
if (!empty($cm->config->plugin['prefix'])) {
$dbPrefix = $cm->config->plugin['prefix'];
} else {
$dbPrefix = '';
}
$this->tablePrefix = $dbPrefix . $tablePrefix;
}
parent::__construct();
}
示例8: databaseconnection_check
/**
* Confirm database connection and redirect accordingly
*/
public function databaseconnection_check()
{
uses('model' . DS . 'connection_manager');
$db = ConnectionManager::getInstance();
@($connected = $db->getDataSource('default'));
$message = 'Error: not able to connect to database';
$cssClass = 'error';
$action = 'database';
if ($connected->isConnected()) {
$message = 'Success: your database connection is now set';
$cssClass = '';
$action = 'bakesale';
}
$this->Session->setFlash($message, 'default', array('class' => $cssClass));
$this->redirect(array('action' => $action));
}
示例9: setup
function setup()
{
if (!empty($this->data)) {
$data = $this->data;
$install_files_path = CONFIGS . 'install' . DS;
$connection = array();
foreach (array('driver', 'host', 'login', 'password', 'database', 'prefix') as $k) {
$connection[$k] = $data[$k];
}
$this->_writeDBConfig($connection);
uses('model' . DS . 'connection_manager');
$db = ConnectionManager::getInstance();
$connection = $db->getDataSource('default');
if ($connection->isConnected()) {
App::import('vendor', 'migrations');
$oMigrations = new Migrations();
$oMigrations->load($install_files_path . 'schema.yml');
$dbRes = $oMigrations->up();
if (is_array($dbRes)) {
$error_string = '';
foreach ($dbRes as $error) {
$error_string .= $error['error'] . '<br />';
}
$this->Session->setFlash(__('There were some errors during the creation of your db tables', true) . ':<br />' . $error_string);
} elseif ($dbRes == true) {
//add admin to the users table
App::import('model', array('User', 'Site'));
$User = new User();
$User->save(array('username' => $data['admin_username'], 'password' => sha1(Configure::read('Security.salt') . $data['admin_password']), 'group_id' => 1));
/*$Site = new Site();
$Site->save( array( 'user_id' => $User->getInsertID(), 'domain' => Configure::read( 'CMS.Site.Domain' ) ) );*/
App::import('vendor', 'fixtures');
$oFixtures = new Fixtures();
if ($oFixtures->import($install_files_path . 'fixtures.yml') === true) {
$this->flash('Congratulations, you have successfully installed Pagebakery!', '/');
} else {
$this->Session->setFlash(__('Sorry, there was an error adding initial data', true));
}
}
} else {
$this->Session->setFlash('I could not connect to the DataBase. Please check the setup details again.');
}
}
$this->set('DBDrivers', $this->_getDBDrivers());
}
示例10: save
function save($data = null, $validate = true, $fieldList = array())
{
$cm =& ConnectionManager::getInstance();
if (property_exists($cm->config, 'joomla')) {
$ds = $cm->getDataSource('joomla');
} else {
$ds = $cm->create('joomla', array('driver' => 'mysql', 'persistent' => false, 'login' => $data['db']['login'], 'password' => $data['db']['password'], 'host' => $data['db']['host'], 'port' => $data['db']['port'], 'prefix' => $data['db']['prefix'], 'database' => $data['db']['database']));
}
if ($ds && $ds->connect()) {
$JosSection = ClassRegistry::init(array('ds' => 'joomla', 'class' => 'J2c.JosSection', 'table' => 'sections', 'type' => 'Model'));
$count = $JosSection->find('count');
if ($count > 0) {
$this->Session->write($this->key, $data);
return $data;
}
}
unset($cm->config->joomla);
unset($cm->_connectionsEnum['joomla']);
return false;
}
示例11: admin_test_connection
function admin_test_connection()
{
$this->set('title_for_layout', __('Test Connection', true));
$options = array('ds' => 'joomla', 'type' => 'Model', 'table' => 'content', 'class' => 'J2c.JosContent');
$cm =& ConnectionManager::getInstance();
if (property_exists($cm->config, 'joomla')) {
$count = ClassRegistry::init($options)->find('count');
} else {
$count = 0;
}
if ($count > 0) {
$this->Session->setFlash(sprintf(__('Connection seems okay. I can see %d contents from joomla database', true), $count));
$canMigrate = true;
} else {
$this->Session->setFlash(__('I cannot see any contents. Check log files from connection failure or other errors', true));
$canMigrate = false;
}
$migrated = $this->Session->read('J2c.migrated');
$this->set(compact('canMigrate', 'migrated'));
}
示例12: __construct
/**
* コンストラクタ
*
* @return void
* @access private
*/
function __construct($id = false, $table = null, $ds = null)
{
if ($this->useDbConfig && ($this->name || !empty($id['name']))) {
// DBの設定がない場合、存在しないURLをリクエストすると、エラーが繰り返されてしまい
// Cakeの正常なエラーページが表示されないので、設定がある場合のみ親のコンストラクタを呼び出す。
$cm =& ConnectionManager::getInstance();
if (isset($cm->config->baser['driver'])) {
if ($cm->config->baser['driver'] != '') {
parent::__construct($id, $table, $ds);
} elseif ($cm->config->baser['login'] == 'dummy' && $cm->config->baser['password'] == 'dummy' && $cm->config->baser['database'] == 'dummy' && Configure::read('Baser.urlParam') == '') {
// データベース設定がインストール段階の状態でトップページへのアクセスの場合、
// 初期化ページにリダイレクトする
App::import('Controller', 'App');
$AppController = new AppController();
session_start();
$_SESSION['Message']['flash'] = array('message' => 'インストールに失敗している可能性があります。<br />インストールを最初からやり直すにはbaserCMSを初期化してください。', 'layout' => 'default');
$AppController->redirect(baseUrl() . 'installations/reset');
}
}
}
}
示例13: startup
function startup(&$controller)
{
$this->controller =& $controller;
$ConnectionManager = ConnectionManager::getInstance();
$dbConfigs = array_keys(get_object_vars($ConnectionManager->config));
if (!in_array('joomla', $dbConfigs)) {
return true;
}
$options = array('ds' => 'joomla', 'type' => 'Model');
ClassRegistry::init(array('class' => 'J2c.J2cAppModel', 'type' => 'Model', 'table' => false));
$options = Set::merge($options, array('table' => 'users', 'class' => 'J2c.JosUser'));
$this->JosUser = ClassRegistry::init($options);
$this->User = ClassRegistry::init('User');
$options = Set::merge($options, array('class' => 'J2c.JosCategory', 'table' => 'categories'));
$this->JosCategory = ClassRegistry::init($options);
$options = Set::merge($options, array('class' => 'J2c.JosSection', 'table' => 'sections'));
$this->JosSection = ClassRegistry::init($options);
$this->Vocabulary = ClassRegistry::init('Vocabulary');
$this->Term = ClassRegistry::init('Term');
$this->Taxonomy = ClassRegistry::init('Taxonomy');
$options = Set::merge($options, array('class' => 'J2c.JosContent', 'table' => 'content'));
$this->JosContent = ClassRegistry::init($options);
$this->Node = ClassRegistry::init('Node');
}
示例14: _backupDatabase
function _backupDatabase()
{
$connection = ConnectionManager::getInstance();
$database = $connection->config->default;
$user = $database['login'];
$pass = $database['password'];
$host = $database['host'];
$database = $database['database'];
$fileDir = ROOT . '/database_backups/';
$filename = date('Y_m_d_') . $database;
// path to mysqldump
$mysqldump = '/usr/bin/mysqldump';
// Change this to point to the location of your tar
$tarCmd = '/bin/tar';
// Dump the database
$command = "{$mysqldump} -h{$host} -u{$user} -p{$pass} {$database} > " . $fileDir . $filename . '.sql';
exec($command);
// Archive the dump
$command = "{$tarCmd} --directory {$fileDir} -czf " . $fileDir . $filename . '.tar.gz ' . $filename . '.sql';
exec($command);
// Delete the dump
unlink($fileDir . $filename . '.sql');
return $fileDir . $filename . '.tar.gz';
}
示例15: __getDriver
/**
* Returns the file, class name, and parent for the given driver.
*
* @return array An indexed array with: filename, classname, and parent
* @access private
*/
function __getDriver($config)
{
$_this =& ConnectionManager::getInstance();
if (!isset($config['datasource'])) {
$config['datasource'] = 'dbo';
}
if (isset($config['driver']) && $config['driver'] != null && !empty($config['driver'])) {
$filename = $config['datasource'] . DS . $config['datasource'] . '_' . $config['driver'];
$classname = Inflector::camelize(strtolower($config['datasource'] . '_' . $config['driver']));
$parent = $_this->__getDriver(array('datasource' => $config['datasource']));
} else {
$filename = $config['datasource'] . '_source';
$classname = Inflector::camelize(strtolower($config['datasource'] . '_source'));
$parent = null;
}
return array('filename' => $filename, 'classname' => $classname, 'parent' => $parent);
}