本文整理匯總了PHP中Install::mysql方法的典型用法代碼示例。如果您正苦於以下問題:PHP Install::mysql方法的具體用法?PHP Install::mysql怎麽用?PHP Install::mysql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Install
的用法示例。
在下文中一共展示了Install::mysql方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Install
//實例化模型類
$sql = "CREATE DATABASE IF NOT EXISTS `" . $config['DB_NAME'] . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;";
$model->query($sql);
//如果指定數據庫不存在,則嘗試創建
$model->db->select_db($config['DB_NAME']);
//選擇數據庫
$ins = new Install();
//實例化數據庫安裝類
$DB_PREFIX = in($_POST['DB_PREFIX']);
if (empty($DB_PREFIX)) {
$DB_PREFIX = 'dc_';
}
if ($_POST['test']) {
$sql_array = Install::mysql('../data/test.sql', 'dc_', $DB_PREFIX);
} else {
$sql_array = Install::mysql('../data/db.sql', 'dc_', $DB_PREFIX);
}
//執行數據庫操作
foreach ($sql_array as $sql) {
$model->db->query($sql);
//安裝數據
}
//修改配置文件
$config_array = array();
foreach ($config as $key => $value) {
$config_array["config['" . $key . "']"] = $value;
}
if (!set_config($config_array)) {
cpError::show('配置文件寫入失敗!');
}
//安裝成功,創建鎖定文件
示例2: install
public function install()
{
$tmp_a = str_replace('/install', '', __ROOT__);
$tmp_b = strrpos($tmp_a, '/');
$db_config = array('DB_HOST' => $this->config['DB_HOST'], 'DB_PORT' => $this->config['DB_PORT'], 'DB_NAME' => $this->config['DB_NAME'], 'DB_USER' => $this->config['DB_USER'], 'DB_PWD' => $this->config['DB_PWD'], 'DB_PREFIX' => $this->config['DB_PREFIX'], 'site_url' => 'http://' . $_SERVER['HTTP_HOST'] . substr($tmp_a, 0, $tmp_b + 1));
if (!$this->create_db($db_config)) {
$this->assign('error', '數據庫創建失敗,請檢測本帳號是否有權限!');
$this->display('error');
exit;
}
$DB_PREFIX = $db_config['DB_PREFIX'];
if (empty($DB_PREFIX)) {
$DB_PREFIX = 'ecs_';
}
//處理安裝SQL的字段兼容
if (!$this->get_column($db_config, $DB_PREFIX . 'users', 'aite_id')) {
$growing = "ALTER TABLE `ecs_users` ADD COLUMN `aite_id` VARCHAR(40) NOT NULL COMMENT '第三方登陸標識';";
$this->update_install_sql($growing);
}
if (!$this->get_column($db_config, $DB_PREFIX . 'goods', 'sales_count')) {
$growing = "ALTER TABLE `ecs_goods` ADD COLUMN `sales_count` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `click_count`;";
$this->update_install_sql($growing);
}
if (!$this->get_column($db_config, $DB_PREFIX . 'brand', 'brand_banner')) {
$growing = "ALTER TABLE `ecs_brand` ADD COLUMN `brand_banner` VARCHAR(80) NOT NULL COMMENT '商品品牌banner';";
$this->update_install_sql($growing);
}
if (!$this->get_column($db_config, $DB_PREFIX . 'category', 'cat_ico')) {
$growing = "ALTER TABLE `ecs_category` ADD COLUMN `cat_ico` varchar(255) NOT NULL;";
$this->update_install_sql($growing);
}
if (!$this->get_column($db_config, $DB_PREFIX . 'users', 'wxch_bd')) {
$growing = "ALTER TABLE `ecs_users` ADD COLUMN `wxch_bd` CHAR(2) NOT NULL AFTER `passwd_answer`;";
$this->update_install_sql($growing);
}
if (!$this->get_column($db_config, $DB_PREFIX . 'users', 'wxid')) {
$growing = "ALTER TABLE `ecs_users` ADD COLUMN `wxid` CHAR(28) NOT NULL AFTER `passwd_answer`;";
$this->update_install_sql($growing);
}
$sql_data = Install::mysql(ROOT_PATH . 'install/install.sql', 'ecs_', $DB_PREFIX);
if (!$this->run_sql($db_config, $sql_data)) {
$this->assign('error', '基礎數據導入失敗,請檢查後手動刪除數據庫重新安裝!');
$this->display('error');
}
if ($this->save_config($db_config)) {
@fopen($this->lockFile, 'w');
$this->display('success');
} else {
$this->assign('error', '配置文件寫入失敗,請檢測config.php是否有寫入權限!');
$this->display('error');
}
}
示例3: importing
/**
* 安裝處理
*/
public function importing()
{
$data = in($_POST);
$configDb = $data['DB'];
if (strpos($configDb['DB_HOST'], ':') !== false) {
$db_host = explode(':', $configDb['DB_HOST']);
$configDb['DB_HOST'] = $db_host[0];
$configDb['DB_PORT'] = $db_host[1];
} else {
$configDb['DB_PORT'] = '3306';
}
$link = @mysql_connect($configDb['DB_HOST'] . ':' . $configDb['DB_PORT'], $configDb['DB_USER'], $configDb['DB_PWD']);
if (!$link) {
$this->msg('數據庫連接失敗,請檢查連接信息是否正確!', false);
}
$mysqlInfo = @mysql_get_server_info($link);
if ($mysqlInfo < '5.0') {
$this->msg('MySql版本低於5.0,無法繼續安裝!', false);
}
$status = @mysql_select_db($configDb['DB_NAME'], $link);
if (!$status) {
$this->msg('數據庫' . $configDb['DB_NAME'] . '不存在,請檢查數據庫!', false);
}
if ($data['agree'] != 1) {
$this->msg('請認真閱讀並同意安裝協議!', false);
}
//設置表前綴
$dbPrefix = $configDb['DB_PREFIX'];
if (empty($dbPrefix)) {
$dbPrefix = 'ecs_';
}
$dbData = ROOT_PATH . 'data/install.sql';
$sqlData = Install::mysql($dbData, 'ecs_', $dbPrefix);
//更新安裝sql文件
if (!model('Install')->get_column($configDb, $dbPrefix . 'order_info', 'mobile_pay')) {
$sqlData[] = "ALTER TABLE `" . $dbPrefix . "order_info` ADD COLUMN `mobile_order` int(1) UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN `mobile_pay` int(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `discount`;";
}
$sqlData[] = "UPDATE `" . $dbPrefix . "touch_shop_config` SET `value` = '" . str_replace('/mobile', '', __URL__) . "' where `code`='shop_url';";
if (!model('Install')->runSql($configDb, $sqlData)) {
$this->msg('數據導入失敗,請檢查後手動刪除數據庫重新安裝!', false);
}
model('Install')->filter_column($configDb, 'touch_shop_config');
//配置shop_config
$this->set_config($configDb);
$this->msg('安裝成功!', true);
}
示例4: init
/**
* 在線升級
*/
public function init()
{
// 開始升級
$do = I('get.do');
$cover = I('cover', 0);
if (empty($do)) {
$this->message(L('upgradeing'), url('init', array('do' => 1, 'cover' => $cover)));
}
// 獲取補丁列表
$pathlist = $this->pathlist();
if (empty($pathlist)) {
$this->message(L('upgrade_success'), url('checkfile'));
}
// 創建緩存文件夾
if (!file_exists(CACHE_PATH . 'upgrade')) {
@mkdir(CACHE_PATH . 'upgrade');
}
foreach ($pathlist as $k => $v) {
$release = str_replace('patch_R', '', basename($v, ".zip"));
// 遠程壓縮包地址
$upgradezip_url = $this->upgrade_path_base . $v;
// 保存到本地地址
$upgradezip_path = CACHE_PATH . 'upgrade' . DIRECTORY_SEPARATOR . $v;
// 解壓路徑
$upgradezip_source_path = CACHE_PATH . 'upgrade' . DIRECTORY_SEPARATOR . basename($v, ".zip");
// 下載壓縮包
@file_put_contents($upgradezip_path, Http::doGet($upgradezip_url));
// 解壓縮
$zip = new Zip();
if ($zip->decompress($upgradezip_path, $upgradezip_source_path) == 0) {
die("Error : unpack the failure.");
}
// 拷貝utf8/upload文件夾到根目錄
$copy_from = $upgradezip_source_path . DIRECTORY_SEPARATOR . $this->patch_charset . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR;
$copy_to = ROOT_PATH;
$this->copyfailnum = 0;
$this->copydir($copy_from, $copy_to, $cover);
// 檢查文件操作權限,是否複製成功
if ($this->copyfailnum > 0) {
// 如果失敗,終止操作
$this->message(L('please_check_filepri'), url('index'));
}
// 執行sql
// sql目錄地址
$sql_path = CACHE_PATH . 'upgrade' . DIRECTORY_SEPARATOR . basename($v, ".zip") . DIRECTORY_SEPARATOR . $this->patch_charset . DIRECTORY_SEPARATOR . 'upgrade' . DIRECTORY_SEPARATOR;
$file_list = glob($sql_path . '*');
if (!empty($file_list)) {
foreach ($file_list as $fk => $fv) {
$file_path = strtolower($fv);
if (in_array(substr($file_path, -3, 3), array('php', 'sql')) && substr($file_path, -10, 10) != 'config.php') {
if (substr($file_path, -3, 3) == 'sql') {
// 更新sql文件
$sqlData = Install::mysql($file_path, 'ecs_', C('DB_PREFIX'));
// 執行sql文件
$model = new EcModel();
if (is_array($sqlData)) {
foreach ($sqlData as $sql) {
@$model->db->query($sql);
}
}
} elseif (strtolower(substr($file_list[$fk], -3, 3)) == 'php' && file_exists($file_path)) {
include $file_path;
}
}
}
}
// 讀取版本號寫入version.php文件
// 配置文件地址
$configpath = CACHE_PATH . 'upgrade' . DIRECTORY_SEPARATOR . basename($v, ".zip") . DIRECTORY_SEPARATOR . $this->patch_charset . DIRECTORY_SEPARATOR . 'upgrade' . DIRECTORY_SEPARATOR . 'version.php';
if (file_exists($configpath)) {
$config = (include $configpath);
// 版本文件地址
$content = "<?php\ndefine('APPNAME', '" . $config['APPNAME'] . "');\ndefine('VERSION', '" . $config['VERSION'] . "');\ndefine('RELEASE', '" . $release . "');\ndefine('ECTOUCH_AUTH_KEY', '" . ECTOUCH_AUTH_KEY . "');";
@file_put_contents(ROOT_PATH . 'data/version.php', $content);
}
// 刪除文件
@unlink($upgradezip_path);
// 刪除文件夾
del_dir($upgradezip_source_path);
// 提示語
$tmp_k = $k + 1;
if (!empty($pathlist[$tmp_k])) {
$next_update = '<br />' . L('upgradeing') . basename($pathlist[$tmp_k], ".zip");
} else {
$next_update;
}
// 是否升級成功
$this->message(basename($v, ".zip") . L('upgrade_success') . $next_update, url('init', array('do' => 1, 'cover' => $cover)));
}
}