当前位置: 首页>>代码示例>>PHP>>正文


PHP SqlUtility类代码示例

本文整理汇总了PHP中SqlUtility的典型用法代码示例。如果您正苦于以下问题:PHP SqlUtility类的具体用法?PHP SqlUtility怎么用?PHP SqlUtility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SqlUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: queryFromFile

function queryFromFile($sql_file_path)
{
    $sqlUtility = new SqlUtility();
    global $db, $progress, $errors;
    $tables = array();
    if (!file_exists($sql_file_path)) {
        $progress[] = $sql_file_path . ': file not exists.';
        return false;
    }
    $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)));
    $sqlUtility->splitSqlFile($pieces, $sql_query);
    foreach ($pieces as $piece) {
        $piece = trim($piece);
        // [0] contains the prefixed query
        // [4] contains unprefixed table name
        if ($_POST['tb_prefix'] || $_POST['tb_prefix'] == '') {
            $prefixed_query = $sqlUtility->prefixQuery($piece, $_POST['tb_prefix']);
        } else {
            $prefixed_query = $piece;
        }
        if ($prefixed_query != false) {
            $prefixed_query[1] = strtoupper($prefixed_query[1]);
            $table = $_POST['tb_prefix'] . $prefixed_query[4];
            if ($prefixed_query[1] == 'CREATE TABLE') {
                if (mysql_query($prefixed_query[0], $db) !== false) {
                    $progress[] = 'Table <strong>' . $table . '</strong> created successfully.';
                } else {
                    if (mysql_errno($db) == 1050) {
                        $progress[] = 'Table <strong>' . $table . '</strong> already exists. Skipping.';
                    } else {
                        $errors[] = 'Table <strong>' . $table . '</strong> creation failed.';
                    }
                }
            } elseif ($prefixed_query[1] == 'INSERT INTO') {
                mysql_query($prefixed_query[0], $db);
            } elseif ($prefixed_query[1] == 'DELETE FROM') {
                mysql_query($prefixed_query[0], $db);
            } elseif ($prefixed_query[1] == 'REPLACE INTO') {
                mysql_query($prefixed_query[0], $db);
            } elseif ($prefixed_query[1] == 'ALTER TABLE') {
                if (mysql_query($prefixed_query[0], $db) !== false) {
                    $progress[] = 'Table <strong>' . $table . '</strong> altered successfully.';
                } else {
                    if (mysql_errno($db) == 1060) {
                        $progress[] = 'Table <strong>' . $table . '</strong> fields already exists. Skipping.';
                    } elseif (mysql_errno($db) == 1091) {
                        $progress[] = 'Table <strong>' . $table . '</strong> fields already dropped. Skipping.';
                    } else {
                        $errors[] = 'Table <strong>' . $table . '</strong> alteration failed.';
                    }
                }
            } elseif ($prefixed_query[1] == 'DROP TABLE') {
                mysql_query($prefixed_query[1] . ' ' . $table, $db);
            } elseif ($prefixed_query[1] == 'UPDATE') {
                mysql_query($prefixed_query[0], $db);
            }
        }
    }
    return true;
}
开发者ID:giuliaforsythe,项目名称:AChecker,代码行数:60,代码来源:common.inc.php

示例2: run_upgrade_sql

function run_upgrade_sql($upgrade_sql_dir, $current_version, $tb_prefix = TABLE_PREFIX, $in_plain_msg = TRUE)
{
    global $progress;
    // add the ending slash '/' to the input direc
    $upgrade_sql_dir = substr($upgrade_sql_dir, -1) == '/' ? $upgrade_sql_dir : $upgrade_sql_dir . '/';
    // get a list of all update scripts minus sql extension
    $files = scandir($upgrade_sql_dir);
    foreach ($files as $file) {
        if (count($file = explode('_', $file)) == 5) {
            $file[4] = substr($file[4], 0, -3);
            $update_files[$file[2]] = $file;
        }
    }
    ksort($update_files);
    foreach ($update_files as $update_file) {
        if (version_compare($current_version, $update_file[4], '<')) {
            //update_one_ver($update_file, $_POST['tb_prefix']);
            $update_file = implode('_', $update_file);
            $sqlUtility = new SqlUtility();
            $sqlUtility->queryFromFile($upgrade_sql_dir . $update_file . 'sql', $tb_prefix, $in_plain_msg);
        }
    }
}
开发者ID:genaromendezl,项目名称:ATutor,代码行数:23,代码来源:upgrade.inc.php

示例3: pico_oninstall_base

 function pico_oninstall_base($module, $mydirname)
 {
     // transations on module install
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'pico_message_append_oninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
         if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
             include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
             $sqlutil = new OldSqlUtility();
         } else {
             include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
             $sqlutil = new SqlUtility();
         }
         $sql_query = trim(file_get_contents($sql_file_path));
         $sqlutil->splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         if (is_array($pieces)) {
             foreach ($pieces as $piece) {
                 $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
                 if (!$prefixed_query) {
                     $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
                     return false;
                 }
                 if (!$db->query($prefixed_query[0])) {
                     $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
                     //var_dump( $db->error() ) ;
                     return false;
                 } else {
                     if (!in_array($prefixed_query[4], $created_tables)) {
                         $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                         $created_tables[] = $prefixed_query[4];
                     } else {
                         $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
                     }
                 }
             }
         }
     }
     // TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path)) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
                     } else {
                         $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
                     }
                 }
             }
         }
         closedir($handler);
     }
     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($mid);
     return true;
 }
开发者ID:nouphet,项目名称:rata,代码行数:98,代码来源:oninstall.php

示例4: xpwiki_oninstall_base

 function xpwiki_oninstall_base($module, $mydirname)
 {
     // transations on module install
     global $ret;
     // TODO :-D
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'xpwiki_message_append_oninstall');
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail', 'xpwiki_message_append_oninstall');
         $ret = array();
     } else {
         if (!is_array($ret)) {
             $ret = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (loading mysql.sql)
     $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
     $prefix_mod = $db->prefix() . '_' . $mydirname;
     if (file_exists($sql_file_path)) {
         $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path, ENT_COMPAT, _CHARSET) . "</b>.<br /> Creating tables...";
         if (is_file(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
             include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
             $sqlutil = new OldSqlUtility();
         } else {
             include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
             $sqlutil = new SqlUtility();
         }
         $sql_query = trim(file_get_contents($sql_file_path));
         // [ MySQL Version >= 5 ] BLOB and TEXT columns cannot be assigned a default value.
         if (is_object($db->conn) && get_class($db->conn) === 'mysqli') {
             $mysql_ver = mysqli_get_server_info($db->conn);
         } else {
             $mysql_ver = mysql_get_server_info();
         }
         if (@$mysql_ver[0] >= 5) {
             $sql_query = str_replace(' default \'\'', '', $sql_query);
         }
         // [ MySQL Version >= 4 ] ENGINE is the preferred term from MySQL 4.0.18 on and TYPE is deprecated.
         if (@$mysql_ver[0] >= 4) {
             $sql_query = str_replace(' TYPE=MyISAM', ' ENGINE=MyISAM', $sql_query);
         }
         $sqlutil->splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         foreach ($pieces as $piece) {
             $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
             if (!$prefixed_query) {
                 $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece, ENT_COMPAT, _CHARSET) . "</b><br />";
                 return false;
             }
             if (!$db->query($prefixed_query[0])) {
                 $ret[] = '<b>' . htmlspecialchars($db->error(), ENT_COMPAT, _CHARSET) . '</b><br />';
                 //var_dump( $db->error() ) ;
                 return false;
             } else {
                 if (!in_array($prefixed_query[4], $created_tables)) {
                     $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b> created.<br />';
                     $created_tables[] = $prefixed_query[4];
                 } else {
                     $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b>.</br />';
                 }
             }
         }
     }
     // TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     $tpl_path = dirname(__FILE__) . '/templates';
     if ($handler = @opendir($tpl_path . '/')) {
         while (($file = readdir($handler)) !== false) {
             if (substr($file, 0, 1) == '.') {
                 continue;
             }
             $file_path = $tpl_path . '/' . $file;
             if (is_file($file_path) && substr($file, -5) == '.html') {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 $tplfile->setVar('tpl_source', file_get_contents($file_path), true);
                 $tplfile->setVar('tpl_refid', $mid);
                 $tplfile->setVar('tpl_tplset', 'default');
                 $tplfile->setVar('tpl_file', $mydirname . '_' . $file);
                 $tplfile->setVar('tpl_desc', '', true);
                 $tplfile->setVar('tpl_module', $mydirname);
                 $tplfile->setVar('tpl_lastmodified', $mtime);
                 $tplfile->setVar('tpl_lastimported', 0);
                 $tplfile->setVar('tpl_type', 'module');
                 if (!$tplfile_handler->insert($tplfile)) {
                     $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> to the database.</span><br />';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
                     // generate compiled file
                     include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
                     include_once XOOPS_ROOT_PATH . '/class/template.php';
                     if (!xoops_template_touch($tplid)) {
                         $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b>.</span><br />';
                     } else {
                         $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> compiled.</span><br />';
                     }
//.........这里部分代码省略.........
开发者ID:nao-pon,项目名称:xpWiki,代码行数:101,代码来源:oninstall.php

示例5: queryFromFile

 /**
  * perform queries from SQL dump file in a batch
  * 
  * @param string $file file path to an SQL dump file
  * 
  * @return bool FALSE if failed reading SQL file or TRUE if the file has been read and queries executed
  */
 function queryFromFile($file)
 {
     if (false !== ($fp = fopen($file, 'r'))) {
         include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
         $sql_queries = trim(fread($fp, filesize($file)));
         SqlUtility::splitMySqlFile($pieces, $sql_queries);
         foreach ($pieces as $query) {
             // [0] contains the prefixed query
             // [4] contains unprefixed table name
             $prefixed_query = SqlUtility::prefixQuery(trim($query), $this->prefix());
             if ($prefixed_query != false) {
                 $this->query($prefixed_query[0]);
             }
         }
         return true;
     }
     return false;
 }
开发者ID:BackupTheBerlios,项目名称:xoops4-svn,代码行数:25,代码来源:mysqldatabase.php

示例6: queryFromFile

 /**
  * perform queries from SQL dump file in a batch
  *
  * @param string $file file path to an SQL dump file
  *
  * @return bool FALSE if failed reading SQL file or
  * TRUE if the file has been read and queries executed
  */
 public function queryFromFile($file)
 {
     if (false !== ($fp = fopen($file, 'r'))) {
         $sql_queries = trim(fread($fp, filesize($file)));
         \SqlUtility::splitMySqlFile($pieces, $sql_queries);
         foreach ($pieces as $query) {
             $prefixed_query = \SqlUtility::prefixQuery(trim($query), $this->prefix());
             if ($prefixed_query != false) {
                 $this->query($prefixed_query[0]);
             }
         }
         return true;
     }
     return false;
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:23,代码来源:Connection.php

示例7: xoops_module_install

function xoops_module_install($dirname)
{
    global $xoopsUser, $xoopsConfig;
    $dirname = trim($dirname);
    $db =& Database::getInstance();
    $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
    $module_handler =& xoops_gethandler('module');
    if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
        $module =& $module_handler->create();
        $module->loadInfoAsVar($dirname);
        $module->setVar('weight', 1);
        $error = false;
        $errs = array();
        $sqlfile =& $module->getInfo('sqlfile');
        $msgs = array();
        $msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>';
        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
            $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
        }
        $msgs[] = '<b>Version:</b> ' . $module->getInfo('version');
        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
            $msgs[] = '<b>Author:</b> ' . trim($module->getInfo('author'));
        }
        $msgs[] = '';
        $errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>';
        if ($sqlfile != false && is_array($sqlfile)) {
            $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE];
            if (!file_exists($sql_file_path)) {
                $errs[] = "SQL file not found at <b>{$sql_file_path}</b>";
                $error = true;
            } else {
                $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br  /> Creating tables...";
                include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
                $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
                $sql_query = trim($sql_query);
                SqlUtility::splitMySqlFile($pieces, $sql_query);
                $created_tables = array();
                foreach ($pieces as $piece) {
                    // [0] contains the prefixed query
                    // [4] contains unprefixed table name
                    $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
                    if (!$prefixed_query) {
                        $errs[] = "<b>{$piece}</b> is not a valid SQL!";
                        $error = true;
                        break;
                    }
                    // check if the table name is reserved
                    if (!in_array($prefixed_query[4], $reservedTables)) {
                        // not reserved, so try to create one
                        if (!$db->query($prefixed_query[0])) {
                            $errs[] = $db->error();
                            $error = true;
                            break;
                        } else {
                            if (!in_array($prefixed_query[4], $created_tables)) {
                                $msgs[] = '&nbsp;&nbsp;Table <b>' . $db->prefix($prefixed_query[4]) . '</b> created.';
                                $created_tables[] = $prefixed_query[4];
                            } else {
                                $msgs[] = '&nbsp;&nbsp;Data inserted to table <b>' . $db->prefix($prefixed_query[4]) . '</b>.';
                            }
                        }
                    } else {
                        // the table name is reserved, so halt the installation
                        $errs[] = '<b>' . $prefixed_query[4] . "</b> is a reserved table!";
                        $error = true;
                        break;
                    }
                }
                // if there was an error, delete the tables created so far, so the next installation will not fail
                if ($error == true) {
                    foreach ($created_tables as $ct) {
                        //echo $ct;
                        $db->query("DROP TABLE " . $db->prefix($ct));
                    }
                }
            }
        }
        // if no error, save the module info and blocks info associated with it
        if ($error == false) {
            if (!$module_handler->insert($module)) {
                $errs[] = 'Could not insert <b>' . $module->getVar('name') . '</b> to database.';
                foreach ($created_tables as $ct) {
                    $db->query("DROP TABLE " . $db->prefix($ct));
                }
                $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $module->name() . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />";
                foreach ($errs as $err) {
                    $ret .= " - " . $err . "<br />";
                }
                $ret .= "</p>";
                unset($module);
                unset($created_tables);
                unset($errs);
                unset($msgs);
                return $ret;
            } else {
                $newmid = $module->getVar('mid');
                unset($created_tables);
                $msgs[] = 'Module data inserted successfully. Module ID: <b>' . $newmid . '</b>';
                $tplfile_handler =& xoops_gethandler('tplfile');
                $templates = $module->getInfo('templates');
//.........这里部分代码省略.........
开发者ID:koki-h,项目名称:xoops_utf8,代码行数:101,代码来源:modulesadmin.php

示例8: installSQLAutomatically

 /**
  * Executes SQL file which xoops_version of $module specifies. This
  * function is usefull for installers, but it's impossible to control
  * for detail.
  * 
  * @static
  * @param XoopsModule $module
  * @param Legacy_ModuleInstallLog $log
  * @note FOR THE CUSTOM-INSTALLER
  */
 function installSQLAutomatically(&$module, &$log)
 {
     $sqlfileInfo =& $module->getInfo('sqlfile');
     $dirname = $module->getVar('dirname');
     if (!isset($sqlfileInfo[XOOPS_DB_TYPE])) {
         return;
     }
     $sqlfile = $sqlfileInfo[XOOPS_DB_TYPE];
     $sqlfilepath = XOOPS_MODULE_PATH . "/{$dirname}/{$sqlfile}";
     if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) {
         require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
         $scanner = new Legacy_SQLScanner();
         $scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
         $scanner->setDirname($module->get('dirname'));
         if (!$scanner->loadFile($sqlfilepath)) {
             $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile));
             return false;
         }
         $scanner->parse();
         $sqls = $scanner->getSQL();
         $root =& XCube_Root::getSingleton();
         $db =& $root->mController->getDB();
         //
         // TODO The following variable exists for rollback, but it is not implemented.
         //
         foreach ($sqls as $sql) {
             if (!$db->query($sql)) {
                 $log->addError($db->error());
                 return;
             }
         }
         $log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED);
     } else {
         require_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
         $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications');
         $root =& XCube_Root::getSingleton();
         $db =& $root->mController->mDB;
         $sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath));
         $sql_query = trim($sql_query);
         SqlUtility::splitMySqlFile($pieces, $sql_query);
         $created_tables = array();
         foreach ($pieces as $piece) {
             // [0] contains the prefixed query
             // [4] contains unprefixed table name
             $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
             if (!$prefixed_query) {
                 $log->addError("{$piece} is not a valid SQL!");
                 return;
             }
             // check if the table name is reserved
             if (!in_array($prefixed_query[4], $reservedTables)) {
                 // not reserved, so try to create one
                 if (!$db->query($prefixed_query[0])) {
                     $log->addError($db->error());
                     return;
                 } else {
                     if (!in_array($prefixed_query[4], $created_tables)) {
                         $log->addReport('  Table ' . $db->prefix($prefixed_query[4]) . ' created.');
                         $created_tables[] = $prefixed_query[4];
                     } else {
                         $log->addReport('  Data inserted to table ' . $db->prefix($prefixed_query[4]));
                     }
                 }
             } else {
                 // the table name is reserved, so halt the installation
                 $log->addError($prefixed_query[4] . " is a reserved table!");
                 return;
             }
         }
     }
 }
开发者ID:nunoluciano,项目名称:uxcl,代码行数:81,代码来源:ModuleInstallUtils.class.php

示例9: executeSQL

 /**
  * Execute module's SQL file - if any
  *
  * @return bool
  */
 function executeSQL()
 {
     $error = false;
     $sqlfile =& $this->getInfo('sqlfile');
     if ($sqlfile != false && is_array($sqlfile)) {
         $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
         $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $this->getVar('dirname') . "/" . $sqlfile[XOOPS_DB_TYPE];
         if (!file_exists($sql_file_path)) {
             $this->setErrors("SQL file not found at <b>{$sql_file_path}</b>");
             $error = true;
         } else {
             $this->setMessage("SQL file found at <b>{$sql_file_path}</b>.<br  /> Creating tables...");
             include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
             $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
             $sql_query = trim($sql_query);
             SqlUtility::splitMySqlFile($pieces, $sql_query);
             $created_tables = array();
             foreach ($pieces as $piece) {
                 // [0] contains the prefixed query
                 // [4] contains unprefixed table name
                 $prefixed_query = SqlUtility::prefixQuery($piece, $GLOBALS['xoopsDB']->prefix());
                 if (!$prefixed_query) {
                     $this->setErrors("<b>{$piece}</b> is not a valid SQL!");
                     $error = true;
                     break;
                 }
                 // check if the table name is reserved
                 if (!in_array($prefixed_query[4], $reservedTables)) {
                     // not reserved, so try to create one
                     if (!$GLOBALS['xoopsDB']->query($prefixed_query[0])) {
                         $this->setErrors($GLOBALS['xoopsDB']->error());
                         $error = true;
                         break;
                     } else {
                         if (!in_array($prefixed_query[4], $created_tables)) {
                             $this->setMessage('&nbsp;&nbsp;Table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b> created.');
                             $created_tables[] = $prefixed_query[4];
                         } else {
                             $this->setMessage('&nbsp;&nbsp;Data inserted to table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b>.');
                         }
                     }
                 } else {
                     // the table name is reserved, so halt the installation
                     $this->setErrors('<b>' . $prefixed_query[4] . "</b> is a reserved table!");
                     $error = true;
                     break;
                 }
             }
             // if there was an error, delete the tables created so far, so the next installation will not fail
             if ($error == true) {
                 foreach ($created_tables as $ct) {
                     //echo $ct;
                     $GLOBALS['xoopsDB']->query("DROP TABLE " . $GLOBALS['xoopsDB']->prefix($ct));
                 }
             }
         }
     }
     return $error;
 }
开发者ID:BackupTheBerlios,项目名称:soopa,代码行数:64,代码来源:module.php

示例10: install

 /**
  * install a module
  *
  * @param string  $mod   module dirname
  * @param boolean $force force query
  *
  * @return bool|XoopsModule|XoopsObject
  */
 public function install($mod = '', $force = false)
 {
     $xoops = Xoops::getInstance();
     $module_handler = $xoops->getHandlerModule();
     $mod = trim($mod);
     try {
         $cnt = $module_handler->getCount(new Criteria('dirname', $mod));
     } catch (DBALException $e) {
         $cnt = 0;
     }
     if ($cnt == 0) {
         /* @var $module XoopsModule */
         $module = $module_handler->create();
         $module->loadInfoAsVar($mod);
         $module->setVar('weight', 1);
         $module->setVar('isactive', 1);
         $module->setVar('last_update', time());
         $install_script = $module->getInfo('onInstall');
         if ($install_script && trim($install_script) != '') {
             XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($install_script)));
         }
         $func = "xoops_module_pre_install_{$mod}";
         // If pre install function is defined, execute
         if (function_exists($func)) {
             $result = $func($module);
             if (!$result) {
                 $this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
                 $this->error = array_merge($this->error, $module->getErrors());
                 return false;
             } else {
                 $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
                 $this->trace = array_merge($this->trace, $module->getMessages());
             }
         }
         // Create tables
         $created_tables = array();
         if (count($this->error) == 0) {
             $schema_file = $module->getInfo('schema');
             $sql_file = $module->getInfo('sqlfile');
             if (!empty($schema_file)) {
                 $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
                 if (!XoopsLoad::fileExists($schema_file_path)) {
                     $this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
                     return false;
                 }
                 $importer = new ImportSchema();
                 $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
                 $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
                 $synchronizer->updateSchema($importSchema, true);
             } elseif (is_array($sql_file) && !empty($sql_file[\XoopsBaseConfig::get('db-type')])) {
                 $xoops->deprecated('Install SQL files are deprecated since 2.6.0. Convert to portable Schemas');
                 $sql_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $sql_file[\XoopsBaseConfig::get('db-type')];
                 if (!XoopsLoad::fileExists($sql_file_path)) {
                     $this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
                     return false;
                 } else {
                     $this->trace[] = sprintf(SystemLocale::SF_SQL_FILE_FOUND, "<strong>{$sql_file_path}</strong>");
                     $this->trace[] = SystemLocale::MANAGING_TABLES;
                     $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
                     $sql_query = trim($sql_query);
                     SqlUtility::splitMySqlFile($pieces, $sql_query);
                     foreach ($pieces as $piece) {
                         // [0] contains the prefixed query
                         // [4] contains unprefixed table name
                         $prefixed_query = SqlUtility::prefixQuery($piece, $xoops->db()->prefix());
                         if (!$prefixed_query) {
                             $this->error[]['sub'] = '<span class="red">' . sprintf(XoopsLocale::EF_INVALID_SQL, '<strong>' . $piece . '</strong>') . '</span>';
                             break;
                         }
                         // check if the table name is reserved
                         if (!in_array($prefixed_query[4], $this->reservedTables) || $mod == 'system') {
                             // not reserved, so try to create one
                             try {
                                 $result = $xoops->db()->query($prefixed_query[0]);
                             } catch (Exception $e) {
                                 $xoops->events()->triggerEvent('core.exception', $e);
                                 $result = false;
                             }
                             if (!$result) {
                                 $this->error[] = $xoops->db()->errorInfo();
                                 break;
                             } else {
                                 if (!in_array($prefixed_query[4], $created_tables)) {
                                     $this->trace[]['sub'] = sprintf(XoopsLocale::SF_TABLE_CREATED, '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>');
                                     $created_tables[] = $prefixed_query[4];
                                 } else {
                                     $this->trace[]['sub'] = sprintf(XoopsLocale::SF_DATA_INSERTED_TO_TABLE, '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>');
                                 }
                             }
                         } else {
                             // the table name is reserved, so halt the installation
                             $this->error[]['sub'] = sprintf(SystemLocale::EF_TABLE_IS_RESERVED, '<strong>' . $prefixed_query[4] . '</strong>');
//.........这里部分代码省略.........
开发者ID:redmexico,项目名称:XoopsCore,代码行数:101,代码来源:module.php

示例11: create_and_switch_db

/* Copyright (c) 2002-2010                                              */
/* http://atutor.ca                                                     */
/* This program is free software. You can redistribute it and/or        */
/* modify it under the terms of the GNU General Public License          */
/* as published by the Free Software Foundation.                        */
/************************************************************************/
// $Id$
if (!defined('AT_INSTALLER_INCLUDE_PATH') || !defined('AT_INCLUDE_PATH')) {
    exit;
}
include AT_INCLUDE_PATH . 'install/install.inc.php';
if (isset($_POST['submit'])) {
    //check DB & table connection
    $db = create_and_switch_db($_POST['db_host'], $_POST['db_port'], $_POST['db_login'], $_POST['db_password'], $_POST['tb_prefix'], $_POST['db_name'], true);
    if (!isset($errors)) {
        $sqlUtility = new SqlUtility();
        $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_schema.sql', $addslashes($_POST['tb_prefix']));
        $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_language_text.sql', $addslashes($_POST['tb_prefix']));
        if (!$errors) {
            print_progress($step);
            unset($_POST['submit']);
            unset($_POST['action']);
            store_steps($step);
            print_feedback($progress);
            echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form">
			<input type="hidden" name="step" value="3" />';
            print_hidden(3);
            echo '<p align="center"><input type="submit" class="button" value="Next &raquo; " name="submit" /></p></form>';
            return;
        }
    }
开发者ID:genaromendezl,项目名称:ATutor,代码行数:31,代码来源:step2.php

示例12: import

 function import($language_sql_file)
 {
     // move sql import class from install/ to include/classes/
     // store the lang def'n in a .ini file and use insertLang
     // after checking if it already exists
     // use the sql class to insert the language into the db
     // check if this language exists before calling this method
     require_once AT_INCLUDE_PATH . 'classes/sqlutility.class.php';
     $sqlUtility = new SqlUtility();
     $sqlUtility->queryFromFile($language_sql_file, TABLE_PREFIX);
 }
开发者ID:genaromendezl,项目名称:ATutor,代码行数:11,代码来源:LanguageEditor.class.php

示例13: dirname

<?php

if (!defined('AT_INCLUDE_PATH')) {
    exit;
}
// directory
$directory = AT_CONTENT_DIR . 'adobe_connect';
if (is_dir($directory) && is_writable($directory)) {
    require AT_INCLUDE_PATH . '../mods/_core/file_manager/filemanager.inc.php';
    if (!clr_dir($directory)) {
        $msg->addError(array('MODULE_UNINSTALL', ' ' . $directory . ' can\'t be removed'));
    }
}
// db
$sqlfilepath = dirname(__FILE__) . '/module.sql';
if (!$msg->containsErrors() && file_exists($sqlfilepath)) {
    require_once AT_INCLUDE_PATH . 'classes/sqlutility.class.php';
    $sqlUtility = new SqlUtility();
    $sqlUtility->revertQueryFromFile($sqlfilepath, TABLE_PREFIX);
}
开发者ID:topwebmaster,项目名称:adobe_connect,代码行数:20,代码来源:module_uninstall.php

示例14: xoops_cp_header

 } else {
     xoops_cp_header();
     ss_adminMenu(-1, _AM_SS_IMPORT);
     $error = false;
     $db =& Database::getInstance();
     $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'comments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource');
     $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br  /> Importing Q&A";
     include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
     $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
     $sql_query = trim($sql_query);
     SqlUtility::splitMySqlFile($pieces, $sql_query);
     $created_tables = array();
     foreach ($pieces as $piece) {
         // [0] contains the prefixed query
         // [4] contains unprefixed table name
         $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
         if (!$prefixed_query) {
             $errs[] = "<b>{$piece}</b> is not a valid SQL!";
             $error = true;
             break;
         }
         // check if the table name is reserved
         if (!in_array($prefixed_query[4], $reservedTables)) {
             // not reserved, so try to create one
             if (!$db->query($prefixed_query[0])) {
                 $errs[] = $db->error();
                 $error = true;
                 break;
             } else {
                 if (!in_array($prefixed_query[4], $created_tables)) {
                     $msgs[] = '&nbsp;&nbsp;Updating <b>' . $db->prefix($prefixed_query[4]) . '</b> table.';
开发者ID:BackupTheBerlios,项目名称:soopa,代码行数:31,代码来源:import.php

示例15: print_hidden

                print_hidden(2);
                print_post_for_step9($_POST);
                echo '<p align="center"><input type="submit" class="button" value=" Next &raquo; " name="submit" /></p></form>';
                return;
            }
            $result = '';
            // Get course code to map encoding/charset
            if ($_POST['convert_type'] == 'all' || $_POST['convert_type'] == 'courses') {
                $query = "SELECT course_id, title FROM " . $_POST['tb_prefix'] . "courses";
                $result = mysql_query($query);
                if (mysql_num_rows($result) <= 0) {
                    return false;
                }
            } else {
                //'Skip' was selected, convert table structure only
                $sqlUtility = new SqlUtility();
                $sqlUtility->queryFromFile(AT_INCLUDE_PATH . 'install/db/atutor_convert_db_to_utf8.sql', $_POST['tb_prefix']);
                $progress[] = 'Database table structure has been converted to UTF-8.';
                print_feedback($progress);
                if (isset($errors)) {
                    print_errors($errors);
                    echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form">
					<input type="hidden" name="step" value="3" />';
                    print_hidden(2);
                    print_post_for_step9($_POST);
                    echo '<p align="center"><input type="submit" class="button" value=" Retry " name="submit" /></p></form>';
                    return;
                }
                echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post" name="form">
					<input type="hidden" name="step" value="3" />';
                echo '<input type="hidden" name="con_step" value="4" />';
开发者ID:vicentborja,项目名称:ATutor,代码行数:31,代码来源:ustep7.php


注:本文中的SqlUtility类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。