97超级碰碰碰久久久_精品成年人在线观看_精品国内女人视频免费观_福利一区二区久久

PHP數(shù)據(jù)庫備份腳本技巧

  • 相關(guān)推薦

PHP數(shù)據(jù)庫備份腳本技巧

  代碼如下:

  // 備份數(shù)據(jù)庫

  $host = "localhost";

  $user = "root"; //數(shù)據(jù)庫賬號

  $password = ""; //數(shù)據(jù)庫密碼

  $dbname = "mysql"; //數(shù)據(jù)庫名稱

  // 這里的賬號、密碼、名稱都是從頁面?zhèn)鬟^來的

  if (!mysql_connect($host, $user, $password)) // 連接mysql數(shù)據(jù)庫

  {

  echo 數(shù)據(jù)庫連接失敗,請核對后再試;

  exit;

  }

  if (!mysql_select_db($dbname)) // 是否存在該數(shù)據(jù)庫

  {

  echo 不存在數(shù)據(jù)庫: . $dbname . ,請核對后再試;

  exit;

  }

  mysql_query("set names utf8");

  $mysql = "set charset utf8; ";

  $q1 = mysql_query("show tables");

  while ($t = mysql_fetch_array($q1))

  {

  $table = $t[0];

  $q2 = mysql_query("show create table `$table`");

  $sql = mysql_fetch_array($q2);

  $mysql .= $sql[Create Table] . "; ";

  $q3 = mysql_query("select * from `$table`");

  while ($data = mysql_fetch_assoc($q3))

  {

  $keys = array_keys($data);

  $keys = array_map(addslashes, $keys);

  $keys = join(`,`, $keys);

  $keys = "`" . $keys . "`";

  $vals = array_values($data);

  $vals = array_map(addslashes, $vals);

  $vals = join(",", $vals);

  $vals = "" . $vals . "";

  $mysql .= " into `$table`($keys) values($vals); ";

  }

  }

  $filename = $dbname . date(Ymjgi) . ".sql"; //存放路徑,默認(rèn)存放到項目最外層

  $fp = fopen($filename, w);

  fputs($fp, $mysql);

  fclose($fp);

  echo "數(shù)據(jù)備份成功";

  ?>

【PHP數(shù)據(jù)庫備份腳本技巧】相關(guān)文章:

MySQL數(shù)據(jù)庫備份守則和方法04-22

PHP+mysql的網(wǎng)站作品在面試的時候如何帶去?導(dǎo)出數(shù)據(jù)庫?07-13

如何iTunes備份07-10

如何備份QQ?07-13

騰訊PHP筆試?07-10

怎樣備份QQ信息07-13

php個人求職簡歷08-15

請問multibit錢包 怎么備份?07-10

網(wǎng)站的腳本是什么意思?腳本用什么編輯,怎么做07-09

PHP心得體會08-02