PHP面向对象的mysql数据库函数封装
2015-09-08 22:19
661 查看
PHP4.0之后的版本很大的优势更加注重面向对象的编程。一般情况下,我们用一般方法进行数据库操作要分开写很多方法。用面向对象的方法会增强开发效率。下面给出面向对象编程的mysql数据库操作相关代码:
<?php
class mysql{
private $host;
private $root;
private $pwd;
private $database;
private $conn;
function __construct($host,$root,$pwd,$database){
$this->host = $host;
$this->root = $root;
$this->pwd = $pwd;
$this->database = $database;
$this->connect();
}
//连接数据库
function connect(){
$this->conn = mysql_connect($host,$root,$pwd);
mysql_select_db($this->database,$this->conn);
mysql_query("set names utf8");
}
//执行mysql语句
function query($sql){
return mysql_query($sql);
}
//返回一行数据
function arr_ay($result){
return mysql_fetch_array($result);
}
//返回结果集数目
function rows($reslt){
return mysql_num_rows();
}
function dbclose(){
mysql_close($this->conn);
}
//数据库的基本操作
//查询语句
function select($biao,$where){
return $this->query("SELECT * FROM '$biao' where" );
}
//插入语句
}
<?php
class mysql{
private $host;
private $root;
private $pwd;
private $database;
private $conn;
function __construct($host,$root,$pwd,$database){
$this->host = $host;
$this->root = $root;
$this->pwd = $pwd;
$this->database = $database;
$this->connect();
}
//连接数据库
function connect(){
$this->conn = mysql_connect($host,$root,$pwd);
mysql_select_db($this->database,$this->conn);
mysql_query("set names utf8");
}
//执行mysql语句
function query($sql){
return mysql_query($sql);
}
//返回一行数据
function arr_ay($result){
return mysql_fetch_array($result);
}
//返回结果集数目
function rows($reslt){
return mysql_num_rows();
}
function dbclose(){
mysql_close($this->conn);
}
//数据库的基本操作
//查询语句
function select($biao,$where){
return $this->query("SELECT * FROM '$biao' where" );
}
//插入语句
}
相关文章推荐
- PHP实现留言本代码
- phpstorm php-cgi not found
- 一个超级简单的php框架
- [PHP自动化-进阶]005.Snoopy采集框架介绍
- PHPer 为什么会被 Javaer 鄙视?
- PHPer 为什么会被 Javaer 鄙视?
- PHP基础语法实例
- 解决vsftpd的530/227/500错误
- ContentProvider,BroadCastReceiver,Service
- hive 使用php脚本来完成map/reduce
- 【ThinkPHP】ThinkPHP下载、部署,Helloworld,消除难看的index.php
- [PHP自动化-进阶]004.Snoopy VS CURL 模拟Discuz.net登陆
- 数据存储:ContentProvider获取联系人
- [Swoole入门]-Ubuntu环境下安装Swoole扩展
- 数据存储详解(四)及四大组件之一 之--->ContentProvider(内容提供者)
- ThinkPHP中通过URL重写隐藏应用的入口文件index.php的相关服务器的配置
- php 相对路径中 ./ 与../的区别
- PHP表单案例
- php表单输入验证
- 使用PHP顶替JS有趣DOM