代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PHP
】
封装的 mysql类, 和sql语句生成类
作者:
Leon_Sine
/ 发布于
2014/12/13
/
712
<?php /** *@create 2014-11-05 *@author JustPHP *@description mysql工具类 **/ class DB { private $host = 'localhost'; private $user = 'root'; private $pwd = 'root'; private $port = '3306'; private $dbname = 'test'; private $resource = null; private static $handle = null; private static $isConnect = false; private function __construct($server) { $this->host = $server['host']; $this->user = $server['user']; $this->pwd = $server['pwd']; $this->port = $server['port']; $this->dbname = $server['dbname']; $this->connect(); }//End of function public static function getInstance($server) { if( self::$isConnect ) { return self::$handle; } self::$handle = new self($server); self::$isConnect = true; return self::$handle; }//End of funtion private function connect() { $this->resource = mysql_connect($this->host.':'.$this->port, $this->user, $this->pwd ) or $this->error("connect fail"); mysql_select_db($this->dbname, $this->resource); return true; } private function getSql($sql) { $operate = array('insert', 'delete', 'update', 'select', 'create'); return $sql; } public function query($sql) { $sql = $this->getSql($sql); mysql_query("SET NAMES UTF8"); $query_result = mysql_query($sql, $this->resource) or $this->error("query fail"); return $query_result; } public function getQueryResult($sql) { $query_result = $this->query($sql); $result = array(); if( !$query_result ) { return $result; } while ( $row = mysql_fetch_assoc($query_result) ) { $result[] = $row; } $result['rows'] = mysql_num_rows($query_result); $query_result = null; return $result; } public function getInsertResult($sql) { $query_result = $this->query($sql); if( !$query_result ) { return false; } return mysql_insert_id($this->resource); } public function getUpdateResult($sql) { $query_result = $this->query($sql); if( !$query_result ) { return false; } return mysql_affected_rows($this->resource); } public function getDeleteResult($sql) { return $this->getUpdateResult($sql); } public function close_connect() { self::$handle = null; self::$isConnect = false; mysql_free_result($this->resource); $this->resource = null; } private function error($msg='') { $msg = "$msg--->>".mysql_error(); die($msg); } }//End of class ?> <?php /**+--------------------------------- *@create 2014-11-13 *@author JustPhp *@description DB数据整理类 **+--------------------------------*/ class DbTool { private $primary_key = 'id'; public function __construct($primary_key=null) { if( !empty($primary_key) ) { $this->primary_key = $primary_key; } } public function getInsertSql($data, $table) { $sql = $key_str = $value_str = ""; foreach($data as $key=>$value) { $key_str .= "{$key}, "; $value_str .= "'{$value}', "; } $key_str = trim($key_str, ', '); $value_str = trim($value_str, ', '); $sql = "INSERT INTO {$table}({$key_str}) VALUES({$value_str})"; $data=null; $key_str=null; $value_str=null; return $sql; } public function getUpdateSql($data, $table) { $pk = $this->primary_key; $id = $data[$pk]; unset($data[$pk]); $sql = $key_value = ""; foreach($data as $key=>$value) { $key_value .= "{$key}='{$value}', "; } $key_value = trim($key_value, ', '); $sql = "UPDATE {$table} SET {$key_value} WHERE $pk='{$id}'"; $data=null; $key_value=null; return $sql; } public function getQuerySql($condition, $table) { $field = empty($condition['field']) ? '*': $condition['field']; $sql = "SELECT {$field} FROM {$table} "; if( isset($condition['where']) ) { $sql .= "WHERE {$condition['where']} "; } if( isset($condition['groupby']) ) { $sql .= "GROUP BY {$condition['groupby']} "; } if( isset($condition['orderby']) ) { $sql .= "ORDER BY {$condition['orderby']} "; } if( isset($condition['limit']) ) { $sql .= "LIMIT {$condition['limit']} "; } $condition=null; return $sql; } public function getDeleteSql($id, $table) { $pk = $this->primary_key; $sql = "DELETE FROM {$table} WHERE $pk='{$id}' "; return $sql; } } ?>
试试其它关键字
mysql类
同语言下
.
用net匹配并替换iOS标准的emoji表情符号
.
处理带Emoji表情的的字符串
.
获取微信昵称时 过滤特殊字符
.
通过判断上传文件的头字符来判断文件的类型
.
模拟百度URL加密解密算法
.
以太坊检查地址是否合法
.
实现crontab解析类
.
获取每个月的开始和结束时间
.
图片上传工具类
.
APP手机应用信息采集
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Leon_Sine
贡献的其它代码
(
7
)
.
封装的 mysql类, 和sql语句生成类
.
精确判断IE版本
.
客户端缓存相关函数封装
.
解决跨浏览器下PHP下载文件名中的中文乱码问题
.
列表去重
.
shell脚本重启tomcat
.
创建线程实例
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3