|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
掌握静态网页的制作技术是学习开发网站的先决条件,这一点就讲到这里,因为这篇文章不是教程文章,也就不对技术进行深入的刨析了。mysql <LI class=content id=pre_1152192582>/*************************************
mysql毗连类完成 -write by 三千
**************************************/
/*
利用办法(可以履行普通mysql号令,insert, delete select update)
在文件前,需求加载办法
require("mysql.class.php")
$db=new dbMysql; 加载类
$db->dbServer="localhost";
$db->dbUser="root";
$db->dbPwd="";
$db->dbDatabase="";
$db->dbConnect(); query($sql,$database);
query_first($sql,$database);
fetch_array($sql,$database);
count_records($table,$index,$where,$database);)//为失掉一个表纪录的数量,$table为表名,$index为key,$where为前提,$dbbase为数据库,后两个可以不选
*/
class db_Mysql
{
var $usepconnect;
var $dbSever;
var $dbDatabase;
var $dbbase;
var $dbUser;
var $dbPwd;
var $dbLink;
var $query_id;// 履行query号令的指针
var $num_rows;// 前往的条目数
var $insert_id;// 传回最初一次利用 INSERT 指令的 ID
var $affected_rows;// 传回query号令所影响的列数量
// INSERT、UPDATE 或 DELETE 所影响的列 (row) 数量。
// delete 假如不带where,那末则前往0
function dbconnect($dbbase,$usepconnect)
{
//global $usepconnect;
if($usepconnect==1)
$this->dbLink=@mysql_pconnect($this->dbServer,$this->dbUser,$this->dbPwd);//long connect
else
$this->dbLink=@mysql_connect($this->dbServer,$this->dbUser,$this->dbPwd);//short connect
//$this->dbhalt($this->dbbase);
if(!$this->dbLink) $this->dbhalt("exsiting error when connecting!");
if($this->dbbase=="") $this->dbbase=$this->dbDatabase;
if(dbbase,$this->dbLink">!@mysql_select_db($this->dbbase,$this->dbLink))
$this->dbhalt("can't use this database,please check database!");
} // end func() connect database
//change database
function dbchange_db($dbbase){
$this->dbconnect($dbbase);
}
function dbquery($sql){
//if($dbbase!="") $this->dbchange_db($dbbase);
$this->query_id=mysql_query($sql);
//print($query_id);
if(!$this->query_id) $this->dbhalt("wrong sql sentence!".$sql);
return $this->query_id;
}
function dbquery_first($sql,$dbbase){
$query_id=dbquery($sql,$dbbase);
$returnarray=mysql_fetch_array($query_id);
$this->num_rows=mysql_num_rows($query_id);
$this->dbfree_result($query_id);
return $returnarray;
}
function dbhalt($errmsg){
$msg="
database is wrong!
";
$msg=$errmsg;
echo"$msg";
die();
}
function dbfetch_array($sql,$dbbase,$type){
$query_id=$this->dbquery($sql,$dbbase);
$this->numrows=mysql_num_rows($query_id);
for($i=0;$i<$this->numrows;$i++){
if($type==0)
$array[$i]=mysql_fetch_array($query_id);
else
$array[$i]=mysql_fetch_array($query_id);
}
$this->dbfree_result($query_id);
return $array;
}
function dbdelete($sql,$dbdase){
$query_id=$this->dbquery($sql,$dbbase);
$this->affected_rows=mysql_affected_rows($this->dbLink);
$this->free_reuslt($query_id);
}
function dbinsert($sql,$dbbase){
$query_id=$this->dbquery($sql,$dbbase);
$this->insert_id=mysql_insert_id($this->dbLink);
$this->affected_rows=mysql_affected_rows($this->dbLink);
$this->free_reuslt($query_id);
}
function dbupdate($sql,$dbbase){
$query_id=$this->dbquery($sql,$dbbase);
$this->insert_id=mysql_insert_id($this->dbLink);
$this->affected_rows=mysql_affected_rows($this->dbLink);
$this->free_reuslt($query_id);
}
function dbcount_records($table,$index="id",$where="",$dbbase){
if($dbbase!="")$this->dbchangedb($dbbase);
$result=@mysql_query("select count(".$index.") as 'num' form".$table."where".$where,$this->dbLink);
if(!$result) $this->dbhalt("wrong sql sentence".$sql);
$num=@mysql_result($result,0,"num");
return $num;
}
function dbgetnum($result){
$num=@mysql_numrows($result);
return $num;
}
function dbfree_result($result_id){
@mysql_free_result($query_id);
}
function dbclose(){
mysql_close($this->dbLink);
}
} // end class
$db=new db_Mysql;
$db->dbServer="localhost";
$db->dbUser="root";
$db->dbPwd="";
$db->dbbase="test";
?>
PHP的理解是新手最难迈过的一道门槛,不过你应该感到幸运的是PHP已经最大极限的为了新手而努力了,如果你学过其他的语言,也许会觉得PHP的确相当的简单,但是如果你之前什么都没学过,那么阿弥陀佛,硬着头皮琢磨吧。 |
|