本文整理匯總了PHP中dibi::connect方法的典型用法代碼示例。如果您正苦於以下問題:PHP dibi::connect方法的具體用法?PHP dibi::connect怎麽用?PHP dibi::connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dibi
的用法示例。
在下文中一共展示了dibi::connect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: connectToDatabase
/**
* Spoji se z databzi.
*
* @return Bobr_Bobr
* @throws DibiDriverException
*/
private function connectToDatabase()
{
// @todo odchytavat vyjimku pri nepovedenem spojeni.
$config = new Config();
$connect = dibi::connect(array('driver' => 'postgre', 'string' => ' host=' . $config->dbHost . ' port=' . $config->dbPort . ' dbname=' . $config->dbName . ' user=' . $config->dbUser . ' password=' . $config->dbPassword . '', 'persistent' => $config->dbPersistent), $config->dbConnectionName);
return $this;
}
示例2: startup
function startup()
{
parent::startup();
//vypnutie debugeru + profileru
$config = NEnvironment::getConfig()->database;
$config->profiler = false;
$config->lazy = false;
dibi::connect($config);
//NDebug::enable( TRUE, LOG_DIR);
}
示例3: __construct
public function __construct($branch, $databaseName)
{
$this->_basedir = realpath(dirname(__FILE__) . '/../../../');
require_once $this->_basedir . '/vendor/dg/dibi/dibi/dibi.php';
$this->_databaseName = $databaseName;
$this->_createJumpstormIni($branch);
$this->_setUpEnv();
$this->_verifyMagento($this->_pathToMagentoBaseDir);
\dibi::connect(array('driver' => 'mysql', 'username' => 'root', 'database' => $this->_databaseName));
file_put_contents($this->_getTagFileName(), '');
}
示例4: init
public function init($options)
{
parent::init($options);
$this->sqlDriver = AJXP_Utils::cleanDibiDriverParameters($options["SQL_DRIVER"]);
try {
dibi::connect($this->sqlDriver);
} catch (DibiException $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
exit(1);
}
}
示例5: init
/**
* Initialise the driver.
*
* Expects options containing a key 'SQL_DRIVER' with constructor values from dibi::connect()
*
* Example:
* "SQL_DRIVER" => Array(
* 'driver' => 'sqlite',
* 'file' => "./server/ajxp.db"
* )
*
* Example 2:
* "SQL_DRIVER" => Array(
* 'driver' => 'mysql',
* 'host' => 'localhost',
* 'username' => 'root',
* 'password' => '***',
* 'database' => 'dbname'
* )
*
* @see server/classes/AbstractConfDriver#init($options)
*/
function init($options)
{
parent::init($options);
$this->sqlDriver = $options["SQL_DRIVER"];
try {
dibi::connect($this->sqlDriver);
} catch (DibiException $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
exit(1);
}
}
示例6: init
/**
* Initialise the driver.
*
* Gives the driver a chance to set up it's connection / file resource etc..
*
* @param Array $options array of options specific to the logger driver.
* @access public
*/
function init($options)
{
parent::init($options);
require_once AJXP_BIN_FOLDER . "/dibi.compact.php";
$this->sqlDriver = $options["SQL_DRIVER"];
try {
dibi::connect($this->sqlDriver);
} catch (DibiException $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
exit(1);
}
}
示例7: init
/**
* Initialize the driver.
*
* Gives the driver a chance to set up it's connection / file resource etc..
*
* @param Array $options array of options specific to the logger driver.
* @access public
*/
public function init($options)
{
parent::init($options);
$this->sqlDriver = AJXP_Utils::cleanDibiDriverParameters($options["SQL_DRIVER"]);
try {
dibi::connect($this->sqlDriver);
} catch (DibiException $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
exit(1);
}
$this->queries = AJXP_Utils::loadSerialFile($this->getBaseDir() . "/queries.json", false, "json");
}
示例8: init
/**
* Initialise the driver.
*
* Expects options containing a key 'SQL_DRIVER' with constructor values from dibi::connect()
*
* Example:
* "SQL_DRIVER" => Array(
* 'driver' => 'sqlite',
* 'file' => "./server/ajxp.db"
* )
*
* Example 2:
* "SQL_DRIVER" => Array(
* 'driver' => 'mysql',
* 'host' => 'localhost',
* 'username' => 'root',
* 'password' => '***',
* 'database' => 'dbname'
* )
*
* @see AbstractConfDriver#init($options)
*/
public function init($options)
{
parent::init($options);
require_once AJXP_BIN_FOLDER . "/dibi.compact.php";
$this->sqlDriver = AJXP_Utils::cleanDibiDriverParameters($options["SQL_DRIVER"]);
try {
dibi::connect($this->sqlDriver);
} catch (DibiException $e) {
//throw $e;
echo get_class($e), ': ', $e->getMessage(), "\n";
exit(1);
}
}
示例9: init
function init($options)
{
parent::init($options);
$this->sqlDriver = $options["SQL_DRIVER"];
try {
dibi::connect($this->sqlDriver);
} catch (DibiException $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
exit(1);
}
$this->prefix = $options["PREFIX_TABLE"];
$this->groupid = $options["FEU_GROUPID"];
$this->usersSerFile = $options["USERS_FILEPATH"];
}
示例10: connect
public static function connect($settings = array(), $connection_name = null)
{
$config = Environment::getConfig();
foreach ($config['database'] as $connection_name => $settings) {
try {
dibi::connect($settings, $connection_name);
if ($settings['profiler'] == true) {
dibi::getProfiler()->setFile(APP_DIR . '/log/db.txt');
}
} catch (DibiException $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
}
}
示例11: connect
/**
* Connect to DB, inherit credentials from constructor
*/
private function connect()
{
$this->connectionId = 'DB_CONNECTION_' . md5(implode(',', $this->credentials));
if (defined($this->connectionId) === FALSE) {
$connection = dibi::connect($this->credentials, $this->connectionId);
// Tracy panel
if (TRACY === TRUE) {
$panel = new Dibi\Bridges\Tracy\Panel();
$panel->register($connection);
}
define($this->connectionId, TRUE);
}
$this->connection = dibi::getConnection($this->connectionId);
}
示例12: switchActions
public function switchActions($actionName, $httpVars, $fileVars)
{
if ($actionName != "changes" || !isset($httpVars["seq_id"])) {
return false;
}
require_once AJXP_BIN_FOLDER . "/dibi.compact.php";
dibi::connect($this->sqlDriver);
HTMLWriter::charsetHeader('application/json', 'UTF-8');
$res = dibi::query("SELECT\n [seq] , [ajxp_changes].[repository_identifier] , [ajxp_changes].[node_id] , [type] , [source] , [target] , [ajxp_index].[bytesize], [ajxp_index].[md5], [ajxp_index].[mtime], [ajxp_index].[node_path]\n FROM [ajxp_changes]\n LEFT JOIN [ajxp_index]\n ON [ajxp_changes].[node_id] = [ajxp_index].[node_id]\n WHERE [ajxp_changes].[repository_identifier] = %s AND [seq] > %i\n ORDER BY [ajxp_changes].[node_id], [seq] ASC", $this->computeIdentifier(ConfService::getRepository()), AJXP_Utils::sanitize($httpVars["seq_id"], AJXP_SANITIZE_ALPHANUM));
echo '{"changes":[';
$previousNodeId = -1;
$previousRow = null;
$order = array("path" => 0, "content" => 1, "create" => 2, "delete" => 3);
$relocateAttrs = array("bytesize", "md5", "mtime", "node_path", "repository_identifier");
foreach ($res as $row) {
$row->node = array();
foreach ($relocateAttrs as $att) {
$row->node[$att] = $row->{$att};
unset($row->{$att});
}
if ($row->node_id == $previousNodeId) {
$previousRow->target = $row->target;
$previousRow->seq = $row->seq;
if ($order[$row->type] > $order[$previousRow->type]) {
$previousRow->type = $row->type;
}
} else {
if (isset($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content")) {
echo json_encode($previousRow) . ",";
}
$previousRow = $row;
$previousNodeId = $row->node_id;
}
$lastSeq = $row->seq;
flush();
}
if (isset($previousRow) && ($previousRow->source != $previousRow->target || $previousRow->type == "content")) {
echo json_encode($previousRow);
}
if (isset($lastSeq)) {
echo '], "last_seq":' . $lastSeq . '}';
} else {
$lastSeq = dibi::query("SELECT MAX([seq]) FROM [ajxp_changes]")->fetchSingle();
if (empty($lastSeq)) {
$lastSeq = 1;
}
echo '], "last_seq":' . $lastSeq . '}';
}
}
示例13: databaseHostFactory
/**
* Factory for settings db host.
* @param class Translator
* @param callable
* @return Form
*/
public function databaseHostFactory($translator, callable $onSuccess)
{
$form = $this->forms->create($translator);
$form->addText('host', 'install.db.host')->setRequired('install.form.empty');
$form->addText('user', 'install.db.user')->setRequired('install.form.empty');
$form->addText('password', 'install.db.pass');
$form->addText('database', 'install.db.name')->setRequired('install.form.empty');
$form->addText('prefix', 'install.db.prefix')->setAttribute('placeholder', 'ns_');
// Database drivers.
$drivers = ['mysql' => 'MySQL', 'mysqli' => 'MySQLi'];
$form->addSelect('driver', 'install.db.driver', $drivers)->setRequired();
$form->addSubmit('send', 'install.db.send');
$form->onSuccess[] = function (Form $form, $values) use($onSuccess) {
try {
// Testing database connection.
if (\dibi::connect($values)) {
// Parameters for generate config neon file.
$arr = ['extensions' => ['dibi' => 'Dibi\\Bridges\\Nette\\DibiExtension22'], 'dibi' => ['host' => $values->host, 'username' => $values->user, 'password' => $values->password, 'database' => $values->database, 'driver' => $values->driver, 'lazy' => TRUE, 'substitutes' => ['prefix' => $values->prefix]]];
// Generate and save the configuration file
$this->loader->save($arr, $this->dirs->getAppDir() . '/modules/app.db.neon');
// Removing the old cache for updating the configuration file.
FileSystem::delete($this->dirs->getTempDir() . '/cache/Nette.Configurator');
// Save the installation step into the cache.
$this->steps->setToCache(Steps::Step1, rand(1, 9));
// Save db prefix.
if ($values->prefix) {
$this->sessions->getSessionSection()->prefix = $values->prefix;
}
}
} catch (\Dibi\Exception $e) {
// Server database type error.
if ($e->getCode() == 0) {
$form->addError('install.db.driver.catch');
// Host server not found.
} elseif ($e->getCode() == 2002) {
$form->addError('install.db.host.catch');
// The user or password was not verified.
} elseif ($e->getCode() == 1045) {
$form->addError('install.db.auth.catch');
// The database name was not found
} elseif ($e->getCode() == 1049) {
$form->addError('install.db.name.catch');
}
return;
}
$onSuccess();
};
return $form;
}
示例14: initialize
public static function initialize()
{
$conf = Environment::getConfig('database');
$connection = dibi::connect($conf[$conf->engine]);
if ($conf->engine == 'sqlite') {
$connection->getDriver()->registerFunction('regexp', 'Sqlite::regexp', 2);
} elseif ($conf->engine == 'postgre') {
dibi::addSubst('', '::');
}
if ($conf->profiler) {
$profiler = is_numeric($conf->profiler) || is_bool($conf->profiler) ? new DibiProfiler(array()) : new $conf->profiler();
$profiler->setFile(Environment::expand('%logDir%') . '/sql.log');
$connection->setProfiler($profiler);
}
}
示例15: init
/**
* @param array $connectionParams
*/
public static function init(array $connectionParams)
{
if (!dibi::isConnected()) {
try {
$connection = dibi::connect(array('driver' => $connectionParams['driver'], 'host' => $connectionParams['host'], 'dsn' => 'mysql:host=' . $connectionParams['host'] . ';dbname=' . $connectionParams['db'] . '', 'persistent' => true, 'username' => $connectionParams['user'], 'password' => $connectionParams['pass'], 'database' => $connectionParams['db'], 'charset' => isset($connectionParams['charset']) ? $connectionParams['charset'] : 'utf8', 'result' => array('detectTypes' => true, 'formatDate' => "Y-m-d", 'formatDateTime' => 'Y-m-d H:i:s'), 'profiler' => array('run' => true), 'flags' => MYSQLI_CLIENT_COMPRESS));
$panel = new Dibi\Bridges\Tracy\Panel();
$panel->register($connection);
} catch (DibiException $e) {
dd($e->getMessage());
$view = Core_View::getInstance();
$view->setLayoutFile('$maintenance/db_connect.phtml');
$view->displayLayout();
die;
}
}
}