php中mysql模塊部分功能的簡單封裝
class mysql
{
private $db; // datebase connect
private $result; // mysql result
static private $mysql; // mysql object
private function __construct()
{ // The work before Create an object
$this->db = mysql_connect('localhost','root','');
mysql_select_db('hello', $this->db );
}
public static function getObject()
{ //if have a object,return that object,Not create
if(! self::$mysql instanceof self)
self::$mysql = new self;
return self::$mysql;
}
public function query($sql)
{
$this->result = mysql_query($sql, $this->db);
return $this->result;
}
public function fetch()
{
if( isset($this->result ) )
return mysql_fetch_assoc( $this->result );
}
public function error()
{
return 'error:'.mysql_error();
}
public function num() // for sql select result
{
return mysql_num_rows( $this->result );
}
public function close()
{ // return true or false
return mysql_close( $this->db );
}
}
這樣做看起來就只對可移植有用,其它的作用還體會(huì)不到
- PHP基于單例模式編寫PDO類的方法
- PHP的PDO常用類庫實(shí)例分析
- 詳解PHP中的PDO類
- PHP實(shí)現(xiàn)PDO的mysql數(shù)據(jù)庫操作類
- PHP數(shù)據(jù)庫鏈接類(PDO+Access)實(shí)例分享
- 全新的PDO數(shù)據(jù)庫操作類php版(僅適用Mysql)
- php基于單例模式封裝mysql類完整實(shí)例
- php封裝的mysqli類完整實(shí)例
- php mysql 封裝類實(shí)例代碼
- php封裝的連接Mysql類及用法分析
- php實(shí)現(xiàn)mysql封裝類示例
- PHP訪問MYSQL數(shù)據(jù)庫封裝類(附函數(shù)說明)
- php基于PDO實(shí)現(xiàn)功能強(qiáng)大的MYSQL封裝類實(shí)例
相關(guān)文章
php抽獎(jiǎng)概率算法(刮刮卡,大轉(zhuǎn)盤)
這篇文章主要為大家詳細(xì)介紹了php中獎(jiǎng)概率算法,可用于刮刮卡,大轉(zhuǎn)盤等抽獎(jiǎng)算法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06PHP實(shí)現(xiàn)根據(jù)數(shù)組某個(gè)鍵值大小進(jìn)行排序的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)根據(jù)數(shù)組某個(gè)鍵值大小進(jìn)行排序的方法,涉及php針對數(shù)組的遍歷、排序等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03淺談PHP SHA1withRSA加密生成簽名及驗(yàn)簽
這篇文章主要介紹了PHP SHA1withRSA加密生成簽名及驗(yàn)簽,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03PHP+SQL 注入攻擊的技術(shù)實(shí)現(xiàn)以及預(yù)防辦法
最近在折騰 PHP + MYSQL 的編程。了解了一些 PHP SQL 注入攻擊的知識(shí),總結(jié)一下經(jīng)驗(yàn)。在我看來,引發(fā) SQL 注入攻擊的主要原因,是因?yàn)橐韵聝牲c(diǎn)原因2011-01-01php使用CutyCapt實(shí)現(xiàn)網(wǎng)頁截圖保存的方法
這篇文章主要介紹了php使用CutyCapt實(shí)現(xiàn)網(wǎng)頁截圖保存的方法,結(jié)合實(shí)例形式詳細(xì)分析了CutyCapt的下載、安裝及php使用CutyCapt進(jìn)行截圖與保存的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10解決php使用異步調(diào)用獲取數(shù)據(jù)時(shí)出現(xiàn)(錯(cuò)誤c00ce56e導(dǎo)致此項(xiàng)操作無法完成)
本篇文章是對php中使用異步調(diào)用獲取數(shù)據(jù)時(shí)出現(xiàn)(由于出現(xiàn)錯(cuò)誤c00ce56e而導(dǎo)致此項(xiàng)操作無法完成)的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07session在php5.3中的變化 session_is_registered() is deprecated in
在php 5.3中session_is_registered()已經(jīng)是放棄使用了,大家在使用過程中需要注意一下了2013-11-11