这是一款php中的mysql数据库连接文件代码,如果你正在找这样功能的代码,可以进来看看,非常完整文件
这是一款php教程中的mysql教程数据库教程连接文件代码,如果你正在找这样功能的代码,可以进来看看,非常完整文件。*/
class mysql {
private $db_host; //主机地址
private $db_user; //用户名
private $db_pass; //连接密码
private $db_name; //名称
private $db_charset; //编码private $conn;
private $query_id; //用于判断sql语句是否执行成功
private $result; //结果集
private $num_rows; //结果集中行的数目,仅对select有效
private $insert_id; //上一步 insert 操作产生的 id// 构造/析构函数
function __construct ($db_host,$db_user,$db_pass,$db_name,$db_charset,$conn) {
$this->db_host = $db_host ;
$this->db_user = $db_user ;
$this->db_pass = $db_pass ;
$this->db_name = $db_name ;
$this->db_charset = $db_charset ;
$this->conn = $conn ;
$this->connect();
}function __destruct () {
@mysql_close($this->conn);
}// 连接/选择数据库
public function connect () {
if ($this->conn == 'pconn') {
@$this->conn = mysql_pconnect($this->db_host,$this->db_user,$this->db_pass);
} else {
@$this->conn = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
}
if (!$this->conn) {
$this->show_error('数据库-连接失败:用户名或密码错误!');
}
if (!@mysql_select_db($this->db_name,$this->conn)) {
$this->show_error("数据库-选择失败:数据库 $this->db_name 不可用");
}
mysql_query("set names $this->db_charset");
return $this->conn;
}// query方法
public function query ($sql) {
if ($this->query_id) $this->free_result();
$this->query_id = @mysql_query($sql,$this->conn);
if (!$this->query_id) $this->show_error("sql语句 "$sql" 执行时遇到错误");
return $this->query_id;
}// 查询所有
public function findall ($table_name) {
$this->query("select * from $table_name");
}// mysql_fetch_array
public function fetch_array () {
if ($this->query_id) {
$this->result = mysql_fetch_array($this->query_id);
return $this->result;
}
}// ......
public function fetch_assoc () {
if ($this->query_id) {
$this->result = mysql_fetch_assoc($this->query_id);
return $this->result;
}
}public function fetch_row () {
if ($this->query_id) {
$this->result = mysql_fetch_row($this->query_id);
return $this->result;
}
}public function fetch_object () {
if ($this->query_id) {
$this->result = mysql_fetch_object($this->query_id);
return $this->result;
}
}// 获取 num_rows
public function num_rows () {
if ($this->query_id) {
$this->num_rows = mysql_num_rows($this->query_id);
return $this->num_rows;
}
}// 获取 insert_id
public function insert_id () {
return $this->insert_id = mysql_insert_id();
}// 显示共有多少张表
public function show_tables () {
$this->query("show tables");
if ($this->query_id) {
echo "数据库 $this->db_name 共有 ".$this->num_rows($this->query_id)." 张表
";
$i = 1;
while ($row = $this->fetch_array($this->query_id)){
echo "$i -- $row[0]
";
$i ++;
}
}
}// 显示共有多少个数据库
public function show_dbs(){
$this->query("show databases");
if ($this->query_id) {
echo "共有数据库 ".$this->num_rows($this->query_id)." 个
";
$i = 1;
while ($this->row = $this->fetch_array($this->query_id)){
echo "$i -- ".$this->row[database]."
";
$i ++;
}
}
}// 删除数据库:返回删除结果
public function drop_db ($db_name='') {
if ($db_name == '') {
$db_name = $this->db_name;//默认删除当前数据库
$this->query("drop database $db_name");
}else {
$this->query("drop database $db_name");
}
if ($this->query_id) {
return "数据库 $db_name 删除成功";
}else {
$this->show_error("数据库 $db_name 删除失败");
}
}// 删除数据表:返回删除结果
public function drop_table ($table_name) {
$this->query("drop table $table_name");
if ($this->query_id) {
return "数据表 $table_name 删除成功";
}else {
$this->show_error("数据表 $table_name 删除失败");
}}
// 创建数据库
public function create_db ($db_name) {
$this->query("create database $db_name");
if($this->query_id){
return "数据库 $db_name 创建成功";
}else {
$this->show_error("数据库 $db_name 创建失败");
}
}// 获取数据库版本
public function get_info(){
echo mysql_get_server_info();
}// 显示错误信息
public function show_error ($msg) {
$errinfo = mysql_error();
echo "错误:$msg
返回:$errinfo";
}// 释放内存
public function free_result () {
if ( @mysql_free_result($this->query_id) )
unset ($this->result);
$this->query_id = 0;
}} // end class

PyCharm新手指南:删除项目的实用技巧PyCharm是一款功能强大的Python集成开发环境(IDE),在进行项目开发时,有时候需要删除项目或项目中的文件。本文将介绍在PyCharm中删除项目的实用技巧,并提供具体的代码示例帮助新手更好地理解和应用。1.删除项目删除项目意味着删除整个项目文件夹,这在我们需要清理或重建项目时非常有用。在PyCharm中删

全角英文字母转换为半角形式的实用技巧在现代生活中,我们经常会接触到英文字母,在使用电脑、手机等设备时也经常需要输入英文字母。然而,有时候我们会遇到全角英文字母的情况,而我们需要使用的是半角形式。那么,如何将全角英文字母转换为半角形式呢?下面就为大家介绍一些实用的技巧。首先,全角英文字母和数字是指在输入法中占据一个全角位置的字符,而半角英文字母和数字则是占据一

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

从零开始学习Django框架:实用教程和示例Django是一种流行的PythonWeb应用程序框架,它简化了网站的开发过程。它提供了一套强大的工具和库,帮助开发者构建高效、可扩展和安全的Web应用程序。对于初学者来说,学习Django可能会有些困难,但是通过一些实用的教程和示例,你可以快速上手并了解这个框架的核心概念和用法。本文将带你逐步学习Django框

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

Dreamweaver CS6
视觉化网页开发工具

Dreamweaver Mac版
视觉化网页开发工具

记事本++7.3.1
好用且免费的代码编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。