茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    《PHP編程最快明白》第六講:Mysql數(shù)據(jù)庫(kù)操作
    來(lái)源:易賢網(wǎng) 閱讀:1181 次 日期:2014-05-18 15:02:46
    溫馨提示:易賢網(wǎng)小編為您整理了“《PHP編程最快明白》第六講:Mysql數(shù)據(jù)庫(kù)操作”,方便廣大網(wǎng)友查閱!

    如果一行代碼搞不定你要的功能,該怎么辦?

    答案就是做成一個(gè)類(lèi)--數(shù)據(jù)庫(kù)類(lèi)就產(chǎn)生了。通過(guò)對(duì)函數(shù)的二次封裝,實(shí)現(xiàn)了非常好的重用。要用的時(shí)候再include進(jìn)去。

    在講PHP數(shù)據(jù)庫(kù)之前,先介紹一下Mysql要點(diǎn):大家可以用phpmyadmin學(xué)習(xí)數(shù)據(jù)庫(kù)操作。

    在phpmyadmin里看到編碼這一項(xiàng)全部選中文utf-8就對(duì)了。

    Mysql數(shù)據(jù)庫(kù)類(lèi)型主要是:char(固定空間字符串,多大就是多少個(gè)中文字符)、varchar(可變空間字符串,多大就是初始化多少個(gè)中文字符)、int(整數(shù)多大就是多少位)、float(浮點(diǎn)數(shù))、timestamp(日期,可選建立時(shí)自動(dòng)創(chuàng)建,輸出時(shí)就已經(jīng)是格式化過(guò)的date)、text(文本)、bool(布爾型)

    寫(xiě)sql語(yǔ)句時(shí)SUM()可以統(tǒng)計(jì)值;orderby'id'DESCLIMIT10,10等要活用。

    在phpmyadmin學(xué)一下sql語(yǔ)句增刪改查就行了。

    實(shí)例20Mysql類(lèi)

    代碼如下:

    <?php

    classopmysql{

    private$host='localhost';//服務(wù)器地址

    private$name='root';//登錄賬號(hào)

    private$pwd='';//登錄密碼

    private$dBase='a0606123620';//數(shù)據(jù)庫(kù)名稱(chēng)

    private$conn='';//數(shù)據(jù)庫(kù)鏈接資源

    private$result='';//結(jié)果集

    private$msg='';//返回結(jié)果

    private$fields;//返回字段

    private$fieldsNum=0;//返回字段數(shù)

    private$rowsNum=0;//返回結(jié)果數(shù)

    private$rowsRst='';//返回單條記錄的字段數(shù)組

    private$filesArray=array();//返回字段數(shù)組

    private$rowsArray=array();//返回結(jié)果數(shù)組

    private$idusername=array();

    private$idsubtitle=array();

    //初始化類(lèi)

    function__construct($host='',$name='',$pwd='',$dBase=''){

    if($host!='')

    $this->host=$host;

    if($name!='')

    $this->name=$name;

    if($pwd!='')

    $this->pwd=$pwd;

    if($dBase!='')

    $this->dBase=$dBase;

    $this->init_conn();

    }

    //鏈接數(shù)據(jù)庫(kù)

    functioninit_conn(){

    $this->conn=@mysql_connect($this->host,$this->name,$this->pwd);

    @mysql_select_db($this->dBase,$this->conn);

    mysql_query("setnamesutf8");

    }

    //查詢(xún)結(jié)果

    functionmysql_query_rst($sql){

    if($this->conn==''){

    $this->init_conn();

    }

    $this->result=@mysql_query($sql,$this->conn);

    }

    //取得查詢(xún)結(jié)果字段數(shù)目

    functiongetFieldsNum($sql){

    $this->mysql_query_rst($sql);

    $this->fieldsNum=@mysql_num_fields($this->result);

    }

    //取得查詢(xún)結(jié)果行數(shù)目

    functiongetRowsNum($sql){

    $this->mysql_query_rst($sql);

    if(mysql_errno()==0){

    return@mysql_num_rows($this->result);

    }else{

    return'';

    }

    }

    //取得記錄數(shù)組有索引(單條記錄)

    functiongetRowsRst($sql){

    $this->mysql_query_rst($sql);

    if(mysql_error()==0){

    $this->rowsRst=mysql_fetch_array($this->result,MYSQL_ASSOC);

    return$this->rowsRst;

    }else{

    return'';

    }

    }

    //取得記錄數(shù)組有索引(多條記錄)全部

    functiongetRowsArray($sql){

    $this->mysql_query_rst($sql);

    if(mysql_errno()==0){

    while($row=mysql_fetch_array($this->result,MYSQL_ASSOC)){

    $this->rowsArray[]=$row;

    }

    return$this->rowsArray;

    }else{

    return'';

    }

    }

    //更新、刪除、添加記錄數(shù),返回影響到的行數(shù)

    functionuidRst($sql){

    if($this->conn==''){

    $this->init_conn();

    }

    @mysql_query($sql);

    $this->rowsNum=@mysql_affected_rows();

    if(mysql_errno()==0){

    return$this->rowsNum;

    }else{

    return'';

    }

    }

    //獲取對(duì)應(yīng)的字段值,一條數(shù)字索引,mysql_array_rows才是帶字段索引

    functiongetFields($sql,$fields){

    $this->mysql_query_rst($sql);

    if(mysql_errno()==0){

    if(mysql_num_rows($this->result)>0){

    $tmpfld=@mysql_fetch_row($this->result);

    $this->fields=$tmpfld[$fields];

    }

    return$this->fields;

    }else{

    return'';

    }

    }

    //錯(cuò)誤信息

    functionmsg_error(){

    if(mysql_errno()!=0){

    $this->msg=mysql_error();

    }

    return$this->msg;

    }

    //釋放結(jié)果集

    functionclose_rst(){

    mysql_free_result($this->result);

    $this->msg='';

    $this->fieldsNum=0;

    $this->rowsNum=0;

    $this->filesArray='';

    $this->rowsArray='';

    $this->idsubtitle='';

    $this->idusername='';

    }

    //關(guān)閉數(shù)據(jù)庫(kù)

    functionclose_conn(){

    $this->close_rst();

    mysql_close($this->conn);

    $this->conn='';

    }

    }

    ?>

    實(shí)例21類(lèi)的使用、密碼的md5加密

    代碼如下:

    <?php

    $conne=newopmysql();

    $conne->getRowsArray($sql);

    $conne->close_conn();

    $password=”123456一二三四五六”;

    echomd5($password.”www.***.com”);//輸出為32位的密文,是沒(méi)有解密函數(shù)的,可以實(shí)現(xiàn)簡(jiǎn)單的加密功能。

    ?>

    更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

    2026國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類(lèi)型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專(zhuān)用圖標(biāo)
    聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
    咨詢(xún)QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)