-
- //php implements mysql data import
- define("DbHost", "localhost"); //Database host
- define("DbUser", "root"); //Database user
- define ("DbPass", "password"); //Database password
- mysql_connect(DbHost,DbUser,DbPass) or die("Cannot connect to the server!");
- mysql_create_db("dbname") or die("Cannot create database, maybe You have already installed it");
- mysql_select_db("dbname") or die("Cannot select database, installation failed");
- $fp=fopen("install.sql","r") or die("Cannot open SQL file, please check ");
- $sql=fread($fp,filesize("install.sql"));
- fclose($fp);
- $sql=explode(";",$sql);
- for ($i=0;$i mysql_query($sql[$i]);
- echo "Installation successful";
- ?>
-
Copy code
1, when there is no database statement created in the SQL file
-
- define("DbHost", "localhost"); //Database host
- define("DbUser", "root"); //Database user
- define("DbPass", "password "); //Database password
- define("DbName", "dbname"); //Database name
- mysql_connect(DbHost,DbUser,DbPass) or die("Cannot connect to the server!");
- mysql_create_db(DbName) or die ("Cannot create database, you may have already installed it");
- mysql_select_db(DbName) or die("Cannot select database, installation failed");
- $fp=fopen("install.sql","r") or die("Cannot open SQL file, please check");
- $sql=fread($fp,filesize("install.sql"));
- fclose($fp);
- $sql=explode(";",$ sql);
- for($i=0;$i mysql_query($sql[$i]);
- echo "Installation successful";
- ?>
Copy code
2, the database is created in the SQL file statement (i.e. containing CREATE DATABASE and USE statements)
-
- define("DbHost", "localhost"); //Database host
- define("DbUser", "root"); //Database user
- define("DbPass", "password "); //Database password
- mysql_connect(DbHost,DbUser,DbPass) or die("Cannot connect to the server!");
- $fp=fopen("install.sql","r") or die("Cannot open SQL file, please check ");
- $sql=fread($fp,filesize("install.sql"));
- fclose($fp);
- $sql=explode(";",$sql);
- for( $i=0;$i mysql_query($sql[$i]);
- echo "Installation successful";
- ?>
Copy code
|