源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php中mysql模块部分功能的简单封装

  • 时间:2020-04-15 13:57 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php中mysql模块部分功能的简单封装
[u]复制代码[/u] 代码如下:
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 ); } }
这样做看起来就只对可移植有用,其它的作用还体会不到
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部