详细介绍 mysqli扩展类(一)
2016-04-20 00:00
344 查看
摘要: mysqli扩展,我们有时称之为MySQL增强扩展,可以用于使用 MySQL4.1.3或更新版本中新的高级特性。mysqli扩展在PHP 5及以后版本中包含。
mysqli扩展有一系列的优势,相对于mysql扩展的提升主要有:
• 面向对象接口
• prepared语句支持(译注:关于prepare请参阅mysql相关文档)
• 多语句执行支持
• 事务支持
• 增强的调试能力
• 嵌入式服务支持
我们应该如何使用mysqli类呢?
首先,当然建一个类啦
$mysql = new /mysqli( );
然后,定义查询语句 $query = 'select name from user where id = 8';
$mysql->query($query); //对数据库执行一次查询
mysqli扩展有一系列的优势,相对于mysql扩展的提升主要有:
• 面向对象接口
• prepared语句支持(译注:关于prepare请参阅mysql相关文档)
• 多语句执行支持
• 事务支持
• 增强的调试能力
• 嵌入式服务支持
我们应该如何使用mysqli类呢?
首先,当然建一个类啦
$mysql = new /mysqli( );
mysqli::__construct() ([ string $host= ini_get("mysqli.default_host") [, string $username= ini_get("mysqli.default_user") [, string $passwd= ini_get("mysqli.default_pw") [, string $dbname= "" [, int $port= ini_get("mysqli.default_port") [, string $socket= ini_get("mysqli.default_socket") ]]]]]] ) 从定义可以看出,如果不赋予参数,他默认连接自己给定的数。在一个mysqli类中,是有以下的属性的: MySQLi { /* 属性 */ int $mysqli->affected_rows; 受影响的语句行数 string $mysqli->client_info; 客户端数据库的信息 int $mysqli->client_version; 客户端版本号 string $mysqli->connect_errno; 返回最近一次连接错误的代码 string $mysqli->connect_error; 返回一次连接错误语句 int $errno; 错误代号 array $mysqli->error_list; 错误的列表,每个作为一个关联数组包含errno,错误,和sqlstate string $mysqli->error; 返回一次错误语句 int $mysqli->field_count; string $mysqli->host_info; 本地服务器和连接状态的信息 string $mysqli->protocol_version; 所遵循协议的版本号 string $mysqli->server_info; 服务器数据库信息 int $mysqli->server_version; 服务器数据库版本 string $mysqli->info; 检索最近执行的查询的信息 mixed $mysqli->insert_id; 最后一个查询中使用的自动生成的id string $mysqli->sqlstate; 返回从先前的MySQL SQLSTATE错误操作 int $mysqli->thread_id; 当前数据库连接的线程id号 int $mysqli->warning_count; 最近一次连接 的 警告语句数量 } |
$mysql->query($query); //对数据库执行一次查询
mixed mysqli::query ( string $query[, int $resultmode= MYSQLI_STORE_RESULT ] ) 其中参数 resultmode Either the constant MYSQLI_USE_RESULTor MYSQLI_STORE_RESULTdepending on the desired behavior. By default, MYSQLI_STORE_RESULTis used. If you use MYSQLI_USE_RESULTall subsequent calls will return error Commands out of sync unless you call mysqli_free_result() With MYSQLI_ASYNC(available with mysqlnd), it is possible to perform query asynchronously. mysqli_poll() is then used to get results from such queries. 如果失败则返回false,通过执行SELECT,SHOW,DESCRIBE或EXPLANIN查询会返回一个mysqli_result对象,其他查询则返回true。 什么是mysqli_result对象呢? mysqli_result类代表从一个数据库查询中获取的结果集。详细见文档。 |
相关文章推荐
- MySQL replace函数
- 存储过程处理MySQL中的URL地址,给其加上前缀
- Mysql delimiter
- MySQLdb安装 and 使用
- MySQL存储过程
- mysql主从复制(超简单)
- Mysql学习(二)登陆和创建数据库
- mysql中的元数据锁
- mysql中的隐式提交
- cmd连接mysql的方法详解
- mysql+C#实战四:从数据库中读取数据块和更新数据;
- 跟我一起学习MySQL技术内幕(第五版):(第二章学习日记8)
- 数据库的基本操作(MySQL)
- 数据库mysql服务启动时提示:Windows无法启动服务,1069号错误
- MySQL 主从复制
- mysql主从
- mysql 查询,切换数据库
- MySQL常用函数
- mysql学习笔记(二)
- mysql常用语句