Let's look at how PHP imports the. sql file code
<?php
if (!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 ');
}
}
/* 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);
}
if ($this->version () > ' 5.0.1 ') {
@mysql_query ("SET sql_mode=" ", $this->dblink);
}
} */
@mysql_query (' Set names ' UTF8 ');
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) {//temporarily useless
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 = "$message. = "<meta content=" text/html; Charset=utf-8 "http-equiv=" Content-type ">n";
$message. = "<style type=" Text/css ">n";
$message. = "Body,p,pre {n";
$message. = "font:12px verdana;n";
$message. = "}n";
$message. = "</style>n";
$message. = "$message. = "<body bgcolor=" #FFFFFF "text=" #000000 "link=" #006699 "vlink=" #5493B4 ">n";
$message. = "<p>datebase error:</p><pre><b>". Htmlspecialchars ($msg). </b></pre>n ";
$message. = "<b>mysql error number</b>:". $this->errno (). " N<br/> ";
$message. = "<b>mysql error description</b>:". Htmlspecialchars ($this->error ()). " N<br/> ";
$message. = "<B>DATE</B>:". Date ("y-m-d @ h:i"). " N<br/> ";
$message. = "<b>script</b>: http://". $_server[' http_host '].$_server[' php_self ']. $_server[' query_string ']. " N<br/> ";
$message. = "</body>nEcho $message;
Exit
}
}
/**********************
$SB = new Dbsql ();
$SB->dbconnect (' localhost ', ' root ', ', ', ' fdwp ');
Echo ' FDFD ';
****************************/
?>