澳门新葡萄京娱乐场php 如何导入.sql文件

下面来看看php 如何导入.sql文件的代码

function connect($dbhost, $dbuser, $dbpw, $dbname = ”, $pconnect = 0,
$halt = TRUE, $dbcharset2 = ”) {

?phpif(!defined(‘WEBROOT’)) {die(‘Access Denied!’);}class dbsql {var
$dblink = NULL;var $queryCount = 0;function dbconnect($dbserver,
$dbuser, $dbpwd, $dbname = ”, $pconnect = 0, $charset = ‘utf8’)
{if($pconnect) {if(澳门新葡萄京娱乐场,!$this-dblink = @mysql_pconnect($dbserver, $dbuser,
$dbpwd)) {$this-msghalt(‘Can not connect to MySQL server’);}} else
{if(!$this-dblink = @mysql_connect($dbserver, $dbuser, $dbpwd))
{$this-msghalt(‘Can not connect to MySQL server’);}}

  $func = empty($pconnect) ? ‘mysql_connect’ : ‘mysql_pconnect’;
  if(!$this->link = @$func($dbhost, $dbuser, $dbpw, 1)) {
   $halt && $this->halt(‘Can not connect to MySQL server’);
  } else {
   if($this->version() > ‘4.1’) {
    global $charset, $dbcharset;
    $dbcharset = $dbcharset2 ? $dbcharset2 : $dbcharset;
    $dbcharset = !$dbcharset && in_array(strtolower($charset),
array(‘gbk’, ‘big5’, ‘utf-8’)) ? str_replace(‘-‘, ”, $charset) :
$dbcharset;
    $serverset = $dbcharset ?
‘character_set_connection=’.$dbcharset.’,
character_set_results=’.$dbcharset.’, character_set_client=binary’ :
”;
    $serverset .= $this->version() > ‘5.0.1’ ? ((empty($serverset)
? ” : ‘,’).’sql_mode=”’) : ”;
    $serverset && mysql_query(“SET $serverset”, $this->link);
   }
   $dbname && @mysql_select_db($dbname, $this->link);
  }

/* if($this-version() ‘4.1’) {global $charset,
$dbcharset;if(!$dbcharset in_array(strtolower($charset), array(‘gbk’,
‘big5’, ‘utf-8’))) {$dbcharset = str_replace(‘-‘, ”, $charset);}

 }

if($dbcharset) {@mysql_query(SET character_set_connection=$dbcharset,
character_set_results=$dbcharset, character_set_client=binary,
$this-dblink);}

 function select_db($dbname) {
  return mysql_select_db($dbname, $this->link);
 }

if($this-version() ‘5.0.1’) {@mysql_query(SET sql_mode=”,
$this-dblink);}} */@mysql_query(‘set names utf8’);

 function fetch_array($query, $result_type = MYSQL_ASSOC) {
  return mysql_fetch_array($query, $result_type);
 }

if($dbname) {if(!mysql_select_db($dbname, $this-dblink))
{$this-msghalt(‘Can not connect to MySQL server’);}}}function
select_db($dbname) {return @mysql_select_db($dbname,
$this-dblink);}function query($sql = ”) {if($sql) {if(!($query =
mysql_query($sql,$this-dblink))) {$this-msghalt(MYSQL Query Error!n
$sql);} else {$this-queryCount++;return $query;}} else {return
false;}}function unb_query($sql = ”) {if($sql) {if(!($query =
mysql_unbuffered_query($sql,$this-dblink))) {$this-msghalt(‘MYSQL
Query Error!br /’.$sql.’br /’);} else {$this-queryCount++;return
$query;}} else {return false;}}function fetch_array($query,
$result_type = MYSQL_ASSOC) {return mysql_fetch_array($query,
$result_type);}function fetch_one($sql) {return
$this-fetch_array($this-query($sql));}function affected_rows() {return
mysql_affected_rows($this-dblink);}function num_rows($query, $q =
1){if($q == 1) {return mysql_num_rows($query);} else {return
mysql_num_rows($this-query($query));}//return $query;}function
result($query, $row) {$query = @mysql_result($query, $row);return
$query;}function num_row($query) {//暂时没用return
mysql_num_rows($query);}function free_result($query) {return
mysql_free_result($query);}function insert_id() {return ($id =
mysql_insert_id($this-dblink)) = 0 ? $id :
$this-result($this-query(SELECT last_insert_id()));}function
num_fields($query) {return mysql_num_fields($query);}function
version() {return mysql_get_server_info($this-dblink);}function
close() {return mysql_close($this-dblink);}function
insert_data($tname, $data) {$values = ”;$filed = implode(‘,’,
array_keys($data));$filednum = count($data) – 1;//echo $filednum;$i =
0;foreach($data as $key = $val) {$values .= ‘.$val.’;if($i $filednum)
{$i++;$values .= ‘,’;}}$sql = INSERT INTO .$tname. (.$filed.)
VALUES(.$values.);return $this-unb_query($sql);}function
update_data($tname, $fid, $data, $whereid = ‘id’) {$col =
array();foreach($data as $key = $values){$col[] =
$key.=’.$values.’;}$sql = UPDATE .$tname. SET .implode(‘,’, $col). WHERE
$whereid=’$fid’;return $this-unb_query($sql);}function error() {return
(($this-dblink) ? mysql_error($this-dblink) : mysql_error());}function
errno() {return intval(($this-dblink) ? mysql_errno($this-dblink) :
mysql_errno());}function msghalt($msg = ”) {$message =
htmlnheadn;$message .= meta content=text/html; charset=utf-8 ;$message
.= style type=text/cssn;$message .= body,p,pre {n;$message .= font:12px
Verdana;n;$message .= }n;$message .= /stylen;$message .= /headn;$message
.= body bgcolor=#FFFFFF text=#000000 link=#006699 vlink=#5493B4n;

 function fetch_first($sql) {
  return $this->fetch_array($this->query($sql));
 }

$message .= pDatebase
Error:/ppreb.htmlspecialchars($msg)./b/pren;$message .= bMysql error
number/b: .$this-errno().nbr /;$message .= bMysql error description/b:
.htmlspecialchars($this-error()).nbr /;$message .= bDate/b: .date(Y-m-d
@ H:i).nbr /;$message .= bScript/b:
$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’]
.’?’.$_SERVER[‘QUERY_STRING’].nbr /;

 function result_first($sql) {
  return $this->result($this->query($sql), 0);
 }

$message .= /bodyn/html;echo $message;exit;}}

 function query($sql, $type = ”) {

/**********************$sb = new
dbsql();$sb-dbconnect(‘localhost’,’root’,”,’fdwp’);echo
‘fdfd’;****************************/?

  global $debug, $discuz_starttime, $sqldebug, $sqlspenttimes;

  if(defined(‘SYS_DEBUG’) && SYS_DEBUG) {
   @include_once DISCUZ_ROOT.’./include/debug.func.php’;
   sqldebug();
  }

  $func = $type == ‘UNBUFFERED’ &&
@function_exists(‘mysql_unbuffered_query’) ?
   ‘mysql_unbuffered_query’ : ‘mysql_query’;
  if(!($query = $func($sql, $this->link))) {
   if(in_array($this->errno(), array(2006, 2013)) && substr($type,
0, 5) != ‘RETRY’) {
    $this->close();
    require DISCUZ_ROOT.’./config.inc.php’;
    $this->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, true,
$dbcharset);
    $this->query($sql, ‘RETRY’.$type);
   } elseif($type != ‘SILENT’ && substr($type, 5) != ‘SILENT’) {
    $this->halt(‘MySQL Query Error’, $sql);
   }
  }

  $this->querynum++;
  return $query;
 }

 function affected_rows() {
  return mysql_affected_rows($this->link);
 }

 function error() {
  return (($this->link) ? mysql_error($this->link) :
mysql_error());
 }

 function errno() {
  return intval(($this->link) ? mysql_errno($this->link) :
mysql_errno());
 }

 function result($query, $row = 0) {
  $query = @mysql_result($query, $row);
  return $query;
 }

 function num_rows($query) {
  $query = mysql_num_rows($query);
  return $query;
 }

 function num_fields($query) {
  return mysql_num_fields($query);
 }

 function free_result($query) {
  return mysql_free_result($query);
 }

 function insert_id() {
  return ($id = mysql_insert_id($this->link)) >= 0 ? $id :
$this->result($this->query(“SELECT last_insert_id()”), 0);
 }

 function fetch_row($query) {
  $query = mysql_fetch_row($query);
  return $query;
 }

 function fetch_fields($query) {
  return mysql_fetch_field($query);
 }

 function version() {
  if(empty($this->version)) {
   $this->version = mysql_get_server_info($this->link);
  }
  return $this->version;
 }

 function close() {
  return mysql_close($this->link);
 }

发表评论

电子邮件地址不会被公开。 必填项已用*标注