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


PHP SqlUtility::splitSqlFile方法代码示例

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


在下文中一共展示了SqlUtility::splitSqlFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: revertQueryFromFile

	function revertQueryFromFile($sql_file_path, $table_prefix)
	{
		global $db, $progress, $errors;

		$tables = array();

		if (!file_exists($sql_file_path))
			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);

			$pattern_create_table = "/^CREATE TABLE\s+([`]?)([^`\s]+)\\1(\s)+/siU";
			if (preg_match($pattern_create_table, $piece, $matches))
			{
				$sql = 'DROP TABLE '. $table_prefix . $matches[2];
				mysql_query($sql, $db);
			}
			
			$pattern_insert_lang = "/^INSERT INTO\s+([`]?)language_text\\1\s+.*VALUES.*'.*'.*'(.*)'.*'(.*)'/siU";
			if (preg_match($pattern_insert_lang, $piece, $matches))
			{
				$sql = "DELETE FROM ".$table_prefix."language_text WHERE variable='".$matches[2]."' AND term='".$matches[3]."'";
				mysql_query($sql, $db);
			}
		}

    return TRUE;
  }
开发者ID:radiocontrolled,项目名称:ATutor,代码行数:33,代码来源:sqlutility.class.php

示例3: queryFromFile

 function queryFromFile($sql_file_path, $table_prefix)
 {
     global $db, $progress, $errors;
     include_once AC_INCLUDE_PATH . 'classes/DAO/DAO.class.php';
     $dao = new DAO();
     $tables = array();
     if (!file_exists($sql_file_path)) {
         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 ($table_prefix || $table_prefix == '') {
             $prefixed_query = SqlUtility::prefixQuery($piece, $table_prefix);
         } else {
             $prefixed_query = $piece;
         }
         if ($prefixed_query != false) {
             $table = $table_prefix . $prefixed_query[4];
             $prefixed_query[1] = strtoupper($prefixed_query[1]);
             if (strtoupper($prefixed_query[1]) == 'CREATE TABLE') {
                 if ($dao->execute($prefixed_query[0]) !== false) {
                     $progress[] = 'Table <b>' . $table . '</b> created successfully.';
                 } else {
                     if (mysql_errno($db) == 1050) {
                         $progress[] = 'Table <b>' . $table . '</b> already exists. Skipping.';
                     } else {
                         $errors[] = 'Table <b>' . $table . '</b> creation failed.';
                     }
                 }
             } elseif ($prefixed_query[1] == 'INSERT INTO' || $prefixed_query[1] == 'ALTER TABLE' || $prefixed_query[1] == 'DROP TABLE' || $prefixed_query[1] == 'UPDATE') {
                 $dao->execute($prefixed_query[0]);
             }
         }
     }
     return TRUE;
 }
开发者ID:giuliaforsythe,项目名称:AChecker,代码行数:40,代码来源:sqlutility.class.php


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