内容详情 您现在的位置是: 首页> PHP
php导入数据库sql操作
发布时间:2020-10-18 18:39 已围观:1240
摘要php导入数据库sql操作
//代码导入.sql文件生成数据库:
public function sql_input(){
$file_sql=dirname('sitestar.sql';
$sql_content=file_get_contents($file_sql);
$sql_content = str_replace("\r", "\n", $sql_content);
$config_sql=explode(";\n", $sql_content);
$conn = mysql_connect($dabate['hostname'],$dabate['user'],$dabate['password']);
mysql_query("SET NAMES 'utf8'");
mysql_query("CREATE DATABASE IF NOT EXISTS ".$username." DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;");
mysql_select_db($username, $conn);
foreach ($config_sql as $_value) {
mysql_query($_value.';');
}
mysql_close();
}
赞一个 (6)