Home >Backend Development >PHP Tutorial >Three ways to import sql files with PHP

Three ways to import sql files with PHP

WBOY
WBOYOriginal
2016-07-25 08:54:562100browse
  1. $db = mysql_connect(....);

  2. mysql_select_db(....);

  3. $fp = fopen('somefile.sql' , 'r');

  4. while($fp != feof())
  5. {
  6. $line = fread($fp, 2048);
  7. $line = mysql_real_escape_string($db, $line);
  8. mysql_query($line) ;
  9. }
  10. fclose($fp);

Copy code

2, method 2 of importing sql files in PHP: Reference links: http://www.phpclasses.org/browse/file/24767.html

3. Method 3 of importing sql files in PHP:

  1. exec("SOURCE path/to/*.sql")
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn