0
在我的網站中有一個安裝部分。在那個數據庫導入(數據庫備份文件在根文件夾中)。所以我想列出數據庫後的表名導入完成。這意味着如果有10個表,如果導入table1,則列出table1 is imported
,如果導入表2,則列出table2 is imported
。在數據庫導入操作之間列出表名
我該怎麼做?
這是我的ajax代碼;
function run_install()
{
//alert("process.php");
$.ajax({
type: "POST",
url: "process.php",
data: {method: 'database'},
success: function(msg){
//alert(msg);
}
});
}
這是process.php頁面功能:
if($method == "database") {
$base_url=$_SESSION['base_url'];
$db_name=$_SESSION['db_name'];
$uname=$_SESSION['uname'];
$db_pwd=$_SESSION['pwd'];
$db_host=$_SESSION['db_host'];
clear_db($db_host,$uname,$db_pwd,$db_name);
$conct=mysql_connect($db_host,$uname,$db_pwd);
mysql_select_db($db_name,$conct);
if(mysql_install_db($db_name, "launchrock.sql", $errmsg))
{
}
else{
echo 0;
}
}
function mysql_install_db($dbname, $dbsqlfile, &$errmsg)
{
$result = true;
if(!mysql_select_db($dbname))
{
$result = mysql_query("CREATE DATABASE $dbname");
if(!$result)
{
$errmsg = "could not create [$dbname] db in mysql";
return false;
}
$result = mysql_select_db($dbname);
if(!$result)
{
$errmsg = "could not select [$dbname] database in mysql";
return false;
}
}
else{
$result = mysql_import_file($dbsqlfile, $errmsg);
//$result = "dfgdfG";
return $result;
}
}
function mysql_import_file($filename, &$errmsg)
{
/* Read the file */
$lines = file($filename);
if(!$lines)
{
$errmsg = "cannot open file $filename";
return false;
}
$scriptfile = false;
/* Get rid of the comments and form one jumbo line */
foreach($lines as $line)
{
$line = trim($line);
if([email protected]('^--', $line))
{
$scriptfile.=" ".$line;
}
}
if(!$scriptfile)
{
$errmsg = "no text found in $filename";
return false;
// $status==0;
}
/* Split the jumbo line into smaller lines */
$queries = explode(';', $scriptfile);
/* Run each line as a query */
foreach($queries as $query)
{
$query = trim($query);
if($query == "") { continue; }
if(!mysql_query($query.';'))
{
$errmsg = "query ".$query." failed";
return false;
// $status==0;
}
else
{
$status=1;
}
}
if($status==1)
{
return true;
}
}
您知道ereg正則表達式函數已被棄用,並且很可能在即將發佈的PHP版本中被刪除,對吧? – GordonM 2012-01-02 10:35:55