Php import SQL file (sample code)
/************
- *
- PHP import. SQL file
- Running versions: php5 and php4
- Author: panxp
- Mail: coolpan123@gmail.com
- * Editing: bbs.it-home.org
- *
- *************/
- $ Host = "localhost ";
- $ User = "root ";
- $ Pwd = "";
- $ File_dir = dirname (_ FILE __);
- $ File_name = "bar. SQL ";
- $ Data_base = "test ";
$ Conn = mysql_connect ($ host, $ user, $ pwd );
Mysql_select_db ($ data_base, $ conn );
- /** PHP5 version **/
- $ Get_ SQL _data = file_get_contents ($ file_name, $ file_dir );
/**
- * PHP4 version
- If (file_exists ($ file_dir. "/". $ file_name ))
- {
- $ Get_ SQL _data = fopen ($ file_dir. "/". $ file_name, "r ");
- If (! $ Get_ SQL _data)
- {
- Echo "file cannot be opened ";
- }
- Else
- {
- $ Get_ SQL _data = fread ($ get_ SQL _data, filesize ($ file_dir. "/". $ file_name ));
- }
- }
- ***/
- $ Explode = explode (";", $ get_ SQL _data );
- $ Cnt = count ($ explode );
- For ($ I = 0; $ I
$ SQL = $ explode [$ I];
$ Result = mysql_query ($ SQL );
If ($ result ){
- Echo "success:". $ I. "Queries
";
- }
- Else
- {
- Echo "import failed:". mysql_error ();
- }
- }
- ?>
|