自己写的一个php版的mysql工具类
2015-11-23 17:06
711 查看
<?php
class SqlHelper{
public $conn;
public $host=SAE_MYSQL_HOST_M;
public $port=SAE_MYSQL_PORT;
public $user=SAE_MYSQL_USER;
public $psw=SAE_MYSQL_PASS;
public $db=SAE_MYSQL_DB;
public function __construct(){
$this->conn=mysql_connect($this->host.':'.$this->port,$this->user,$this->psw);
if(!$this->conn){
die('can not connect'.mysql_error());
}
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
//执行查询语句
public function execute_dql($sql){
$res=mysql_query($sql,$this->conn) or die ('query failure111'.mysql_error());
return $res;
}
//执行插入 更新 删除 操作
public function execute_dml($sql){
$b=mysql_query($sql,$this->conn) or die(mysql_errno());
if(!$b){
return 0;//失败
}
else{
if(mysql_affected_rows($this->conn)>0){
return 1;//成功
}
else{
return 2;//没有影响行数
}
}
}
//关闭连接的方法
public function close_connect(){
if(!empty($this->conn)){
mysql_close($this->conn);
}
}
}
?>
class SqlHelper{
public $conn;
public $host=SAE_MYSQL_HOST_M;
public $port=SAE_MYSQL_PORT;
public $user=SAE_MYSQL_USER;
public $psw=SAE_MYSQL_PASS;
public $db=SAE_MYSQL_DB;
public function __construct(){
$this->conn=mysql_connect($this->host.':'.$this->port,$this->user,$this->psw);
if(!$this->conn){
die('can not connect'.mysql_error());
}
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
//执行查询语句
public function execute_dql($sql){
$res=mysql_query($sql,$this->conn) or die ('query failure111'.mysql_error());
return $res;
}
//执行插入 更新 删除 操作
public function execute_dml($sql){
$b=mysql_query($sql,$this->conn) or die(mysql_errno());
if(!$b){
return 0;//失败
}
else{
if(mysql_affected_rows($this->conn)>0){
return 1;//成功
}
else{
return 2;//没有影响行数
}
}
}
//关闭连接的方法
public function close_connect(){
if(!empty($this->conn)){
mysql_close($this->conn);
}
}
}
?>
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复