本文整理汇总了PHP中MySql::tryToConnect方法的典型用法代码示例。如果您正苦于以下问题:PHP MySql::tryToConnect方法的具体用法?PHP MySql::tryToConnect怎么用?PHP MySql::tryToConnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql
的用法示例。
在下文中一共展示了MySql::tryToConnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doUpgrade
//.........这里部分代码省略.........
$this->nextQuickInfo[] = $this->l('The config/settings.inc.php file was not found.');
$this->nextErrors[] = $this->l('The config/settings.inc.php file was not found.');
return false;
}
if (!defined('__PS_BASE_URI__')) {
define('__PS_BASE_URI__', realpath(dirname($_SERVER['SCRIPT_NAME'])) . '/../../');
}
if (!defined('_THEMES_DIR_')) {
define('_THEMES_DIR_', __PS_BASE_URI__ . 'themes/');
}
$oldversion = _PS_VERSION_;
$versionCompare = version_compare(INSTALL_VERSION, $oldversion);
if ($versionCompare == '-1') {
$this->next = 'error';
$this->nextQuickInfo[] = sprintf('current version : %1$s. install version : %2$s', $oldversion, INSTALL_VERSION);
$this->nextErrors[] = sprintf('current version : %1$s. install version : %2$s', $oldversion, INSTALL_VERSION);
$this->nextQuickInfo[] = '[ERROR] version to install is too old ';
$this->nextErrors[] = '[ERROR] version to install is too old ';
return false;
} elseif ($versionCompare == 0) {
$this->next = 'error';
$this->nextQuickInfo[] = $this->l(sprintf('You already have the %s version.', INSTALL_VERSION));
$this->nextErrors[] = $this->l(sprintf('You already have the %s version.', INSTALL_VERSION));
return false;
} elseif ($versionCompare === false) {
$this->next = 'error';
$this->nextQuickInfo[] = $this->l('There is no older version. Did you delete or rename the config/settings.inc.php file?');
$this->nextErrors[] = $this->l('There is no older version. Did you delete or rename the config/settings.inc.php file?');
return false;
}
//check DB access
$this->db;
error_reporting(E_ALL);
$resultDB = MySql::tryToConnect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_);
if ($resultDB !== 0) {
// $logger->logError('Invalid database configuration.');
$this->next = 'error';
$this->nextQuickInfo[] = $this->l('Invalid database configuration');
$this->nextErrors[] = $this->l('Invalid database configuration');
return false;
}
//custom sql file creation
$upgradeFiles = array();
$upgrade_dir_sql = INSTALL_PATH . '/upgrade/sql';
// if 1.4;
if (!file_exists($upgrade_dir_sql)) {
$upgrade_dir_sql = INSTALL_PATH . '/sql/upgrade';
}
if (!file_exists($upgrade_dir_sql)) {
$this->next = 'error';
$this->next_desc = $this->l('unable to find upgrade directory in the install path');
return false;
}
if ($handle = opendir($upgrade_dir_sql)) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' and $file != '..') {
$upgradeFiles[] = str_replace(".sql", "", $file);
}
}
closedir($handle);
}
if (empty($upgradeFiles)) {
$this->next = 'error';
$this->nextQuickInfo[] = sprintf($this->l('Cannot find the sql upgrade files. Please verify that the %s folder is not empty'), $upgrade_dir_sql);
$this->nextErrors[] = sprintf($this->l('Cannot find the sql upgrade files. Please verify that the %s folder is not empty'), $upgrade_dir_sql);
// fail 31
示例2: doUpgrade
/**
* This function now replaces doUpgrade.php or upgrade.php
*
* @return void
*/
public function doUpgrade()
{
// Initialize
// setting the memory limit to 128M only if current is lower
$memory_limit = ini_get('memory_limit');
if (substr($memory_limit, -1) != 'G' and (substr($memory_limit, -1) == 'M' and substr($memory_limit, 0, -1) < 128 or is_numeric($memory_limit) and intval($memory_limit) < 131072)) {
@ini_set('memory_limit', '128M');
}
/* Redefine REQUEST_URI if empty (on some webservers...) */
if (!isset($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == '') {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
}
if ($tmp = strpos($_SERVER['REQUEST_URI'], '?')) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $tmp);
}
$_SERVER['REQUEST_URI'] = str_replace('//', '/', $_SERVER['REQUEST_URI']);
define('INSTALL_VERSION', $this->install_version);
define('INSTALL_PATH', realpath($this->latestRootDir . DIRECTORY_SEPARATOR . 'install'));
define('PS_INSTALLATION_IN_PROGRESS', true);
define('SETTINGS_FILE', $this->prodRootDir . '/config/settings.inc.php');
define('DEFINES_FILE', $this->prodRootDir . '/config/defines.inc.php');
define('INSTALLER__PS_BASE_URI', substr($_SERVER['REQUEST_URI'], 0, -1 * (strlen($_SERVER['REQUEST_URI']) - strrpos($_SERVER['REQUEST_URI'], '/')) - strlen(substr(dirname($_SERVER['REQUEST_URI']), strrpos(dirname($_SERVER['REQUEST_URI']), '/') + 1))));
// define('INSTALLER__PS_BASE_URI_ABSOLUTE', 'http://'.ToolsInstall::getHttpHost(false, true).INSTALLER__PS_BASE_URI);
// XML Header
// header('Content-Type: text/xml');
$filePrefix = 'PREFIX_';
$engineType = 'ENGINE_TYPE';
$mysqlEngine = defined('_MYSQL_ENGINE_') ? _MYSQL_ENGINE_ : 'MyISAM';
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('Europe/Paris');
}
// if _PS_ROOT_DIR_ is defined, use it instead of "guessing" the module dir.
if (defined('_PS_ROOT_DIR_') and !defined('_PS_MODULE_DIR_')) {
define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/');
} else {
if (!defined('_PS_MODULE_DIR_')) {
define('_PS_MODULE_DIR_', INSTALL_PATH . '/../modules/');
}
}
// @todo upgrade_dir_php should be handled by Upgrader class
$upgrade_dir_php = 'upgrade/php';
if (!file_exists(INSTALL_PATH . DIRECTORY_SEPARATOR . $upgrade_dir_php)) {
$upgrade_dir_php = 'php';
if (!file_exists(INSTALL_PATH . DIRECTORY_SEPARATOR . $upgrade_dir_php)) {
$this->next = 'error';
$this->nextDesc = $this->l('php upgrade dir is not found');
$this->nextQuickInfo[] = 'php upgrade dir is missing';
return false;
}
}
define('_PS_INSTALLER_PHP_UPGRADE_DIR_', INSTALL_PATH . DIRECTORY_SEPARATOR . $upgrade_dir_php . DIRECTORY_SEPARATOR);
//old version detection
global $oldversion, $logger;
$oldversion = false;
if (file_exists(SETTINGS_FILE)) {
include_once SETTINGS_FILE;
// include_once(DEFINES_FILE);
$oldversion = _PS_VERSION_;
} else {
$this->next = 'error';
$this->nextQuickInfo[] = $this->l('The config/settings.inc.php file was not found.');
return false;
die('<action result="fail" error="30" />' . "\n");
}
if (!defined('__PS_BASE_URI__')) {
define('__PS_BASE_URI__', realpath(dirname($_SERVER['SCRIPT_NAME'])) . '/../../');
}
if (!defined('_THEMES_DIR_')) {
define('_THEMES_DIR_', __PS_BASE_URI__ . 'themes/');
}
$oldversion = _PS_VERSION_;
$versionCompare = version_compare(INSTALL_VERSION, $oldversion);
if ($versionCompare == '-1') {
$this->next = 'error';
$this->nextQuickInfo[] = $this->l('This installer is too old');
return false;
// die('<action result="fail" error="27" />'."\n");
} elseif ($versionCompare == 0) {
$this->next = 'error';
$this->nextQuickInfo[] = $this->l(sprintf('You already have the %s version.', INSTALL_VERSION));
return false;
die('<action result="fail" error="28" />' . "\n");
} elseif ($versionCompare === false) {
$this->next = 'error';
$this->nextQuickInfo[] = $this->l('There is no older version. Did you delete or rename the config/settings.inc.php file?');
return false;
die('<action result="fail" error="29" />' . "\n");
}
//check DB access
$this->db();
error_reporting(E_ALL);
$resultDB = MySql::tryToConnect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_);
if ($resultDB !== 0) {
// $logger->logError('Invalid database configuration.');
$this->next = 'error';
//.........这里部分代码省略.........