最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php封裝的連接Mysql類及用法分析

 更新時(shí)間:2015年12月10日 10:20:26   作者:happy664618843  
這篇文章主要介紹了php封裝的連接Mysql類及用法,基于php封裝了簡(jiǎn)單的MySQL數(shù)據(jù)庫(kù)的連接、查詢、遍歷等技巧,并附帶說明了其具體用法,需要的朋友可以參考下

本文實(shí)例講述了php封裝的連接Mysql類及用法。分享給大家供大家參考,具體如下:

class mysql{
private $db_name;
private $db_host;
private $db_user;
private $db_pwd;
private $conn;
private $querysql;
private $result;
private $resultarray=array();
private $row;
//創(chuàng)建構(gòu)造函數(shù) 數(shù)據(jù)庫(kù)名 主機(jī)名 用戶名 密碼
function __counstruct($dbname,$dbhost,$dbuser,$dbpwd){
$this->db_name=$dbname;
$this->db_host=$dbhost;
$this->db_pwd=$dbpwd;
$this->db_user=$dbuser;
$this->dbconnect();
$this->selectdb();
}
//連接數(shù)據(jù)庫(kù)
private function db_connect(){
$this->conn=mysql_connect($this->db_host,$this->db_user,$this->db_pwd) or die("Could not Connect MySql Server");
}
private function selectdb(){
mysql_select_db($this->db_name) or die("unable to select dbname")
}
private function query(){
return $this->result=mysql_query($this->querysql);
}
private function get_result($sql){
$this->querysql=$sql;
$this->query();
if($this->get_num()>0){
//mysql_fetch_assoc()和 mysql_fetch_array(,MYSQL_ASSOC)從結(jié)果集中取得一行作為關(guān)聯(lián)數(shù)組 沒有則返回false
while($this->rows=mysql_fetch_array($this->result)){
//賦值 數(shù)組賦值 resultarray[]= 將影響的行數(shù)賦值給數(shù)組
$this->resultarray[]=$this->rows
}
return $this->resultarray;
}
}
//$result返回值為 bool類型 false為沒有數(shù)據(jù)
private function get_num(){
return $this->num=mysql_num_rows($this->result);
}
}
$m=new mysql("testuser","localhost","root","root");
$arreresult=$m->get_result("select * from userinfo");

希望本文所述對(duì)大家php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

临夏市| 西充县| 侯马市| 民丰县| 新宁县| 织金县| 扶沟县| 嵊州市| 大冶市| 堆龙德庆县| 西乡县| 灵寿县| 马鞍山市| 满洲里市| 正阳县| 平乐县| 盈江县| 紫云| 弋阳县| 轮台县| 兴国县| 诸城市| 临夏市| 吉首市| 梁平县| 清徐县| 南京市| 曲沃县| 安仁县| 进贤县| 福建省| 惠东县| 桐乡市| 嘉义市| 阿克苏市| 寻甸| 山丹县| 山东省| 南郑县| 方正县| 商洛市|