php中mysql模塊部分功能的簡單封裝
更新時間:2011年09月30日 23:51:22 作者:
php中mysql模塊部分功能的簡單封裝,很多cms都是封裝了一些mysql的操作代碼類,大家可以參考下。
復(fù)制代碼 代碼如下:
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 );
}
}
這樣做看起來就只對可移植有用,其它的作用還體會不到
您可能感興趣的文章:
- PHP基于單例模式編寫PDO類的方法
- PHP的PDO常用類庫實例分析
- 詳解PHP中的PDO類
- PHP實現(xiàn)PDO的mysql數(shù)據(jù)庫操作類
- PHP數(shù)據(jù)庫鏈接類(PDO+Access)實例分享
- 全新的PDO數(shù)據(jù)庫操作類php版(僅適用Mysql)
- php基于單例模式封裝mysql類完整實例
- php封裝的mysqli類完整實例
- php mysql 封裝類實例代碼
- php封裝的連接Mysql類及用法分析
- php實現(xiàn)mysql封裝類示例
- PHP訪問MYSQL數(shù)據(jù)庫封裝類(附函數(shù)說明)
- php基于PDO實現(xiàn)功能強(qiáng)大的MYSQL封裝類實例
相關(guān)文章
PHP實現(xiàn)根據(jù)數(shù)組某個鍵值大小進(jìn)行排序的方法
這篇文章主要介紹了PHP實現(xiàn)根據(jù)數(shù)組某個鍵值大小進(jìn)行排序的方法,涉及php針對數(shù)組的遍歷、排序等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03PHP+SQL 注入攻擊的技術(shù)實現(xiàn)以及預(yù)防辦法
最近在折騰 PHP + MYSQL 的編程。了解了一些 PHP SQL 注入攻擊的知識,總結(jié)一下經(jīng)驗。在我看來,引發(fā) SQL 注入攻擊的主要原因,是因為以下兩點原因2011-01-01php使用CutyCapt實現(xiàn)網(wǎng)頁截圖保存的方法
這篇文章主要介紹了php使用CutyCapt實現(xiàn)網(wǎng)頁截圖保存的方法,結(jié)合實例形式詳細(xì)分析了CutyCapt的下載、安裝及php使用CutyCapt進(jìn)行截圖與保存的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10解決php使用異步調(diào)用獲取數(shù)據(jù)時出現(xiàn)(錯誤c00ce56e導(dǎo)致此項操作無法完成)
本篇文章是對php中使用異步調(diào)用獲取數(shù)據(jù)時出現(xiàn)(由于出現(xiàn)錯誤c00ce56e而導(dǎo)致此項操作無法完成)的解決方法進(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