一:术语解释:

What is an Extension?

API和扩展不能理解为一个东西,因为扩展不一定暴露一个api给用户

The PDO MySQL driver extension, for example, does not expose an API to the PHP programmer, but provides an interface to the PDO layer above it.

The terms API and extension should not be taken to mean the same thing, as an extension may not necessarily expose an API to the programmer.

参考:http://php.net/manual/zh/mysqlinfo.terminology.php

二:扩展选择:

ext/mysqli PDO_MySQL ext/mysql
PHP version introduced 5.0 5.1 2.0
Included with PHP 5.x Yes Yes Yes
Included with PHP 7.x Yes Yes No
Development status Active Active Maintenance only in 5.x; removed in 7.x
Lifecycle Active Active Deprecated in 5.x; removed in 7.x
Recommended for new projects Yes Yes No
OOP Interface Yes Yes No
Procedural Interface Yes No Yes
API supports non-blocking, asynchronous queries with mysqlnd Yes No No
Persistent Connections Yes Yes Yes
API supports Charsets Yes Yes Yes
API supports server-side Prepared Statements Yes Yes No
API supports client-side Prepared Statements No Yes No
API supports Stored Procedures Yes Yes No
API supports Multiple Statements Yes Most No
API supports Transactions Yes Yes No
Transactions can be controlled with SQL Yes Yes Yes
Supports all MySQL 5.1+ functionality Yes Most No

三:选择mysql驱动(Choosing a library)

mysqli,mysql,pdo底层都是用c写的,有两种底层c库可以使用(mysqlnd library 和 libmysqlclient library),通过编译参数可以更改区别:

mysqlnd更胜一筹;

从php5.3开始,mysqlnd成为php的一部分发布,mysqlnd提供的高级功能有:lazy connections and query caching (这两个功能libmysqlclient library是没有的)

编译配置:

// Recommended, compiles with mysqlnd
$ ./configure --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd // Alternatively recommended, compiles with mysqlnd as of PHP 5.4
$ ./configure --with-mysqli --with-pdo-mysql --with-mysql // Not recommended, compiles with libmysqlclient
$ ./configure --with-mysqli=/path/to/mysql_config --with-pdo-mysql=/path/to/mysql_config --with-mysql=/path/to/mysql_config 注意:可以分别指定mysqli, mysql, pdo 扩展的底层c库
  MySQL native driver (mysqlnd) MySQL client server library (libmysqlclient)
Part of the PHP distribution Yes No
PHP version introduced 5.3.0 N/A
License PHP License 3.01 Dual-License
Development status Active Active
Lifecycle No end announced No end announced
PHP 5.4 and above; compile default (for all MySQL extensions) Yes No
PHP 5.3; compile default (for all MySQL extensions) No Yes
Compression protocol support Yes (5.3.1+) Yes
SSL support Yes (5.3.3+) Yes
Named pipe support Yes (5.3.4+) Yes
Non-blocking, asynchronous queries Yes No
Performance statistics Yes No
LOAD LOCAL INFILE respects the open_basedir directive Yes No
Uses PHP's native memory management system (e.g., follows PHP memory limits) Yes No
Return numeric column as double (COM_QUERY) Yes No
Return numeric column as string (COM_QUERY) Yes Yes
Plugin API Yes Limited
Read/Write splitting for MySQL Replication Yes, with plugin No
Load Balancing Yes, with plugin No
Fail over Yes, with plugin No
Lazy connections Yes, with plugin No
Query caching Yes, with plugin No
Transparent query manipulations (E.g., auto-EXPLAIN or monitoring) Yes, with plugin No

  MySQL native driver (mysqlnd) MySQL client server library (libmysqlclient)
Part of the PHP distribution Yes No
PHP version introduced 5.3.0 N/A
License PHP License 3.01 Dual-License
Development status Active Active
Lifecycle No end announced No end announced
PHP 5.4 and above; compile default (for all MySQL extensions) Yes No
PHP 5.3; compile default (for all MySQL extensions) No Yes
Compression protocol support Yes (5.3.1+) Yes
SSL support Yes (5.3.3+) Yes
Named pipe support Yes (5.3.4+) Yes
Non-blocking, asynchronous queries Yes No
Performance statistics Yes No
LOAD LOCAL INFILE respects the open_basedir directive Yes No
Uses PHP's native memory management system (e.g., follows PHP memory limits) Yes No
Return numeric column as double (COM_QUERY) Yes No
Return numeric column as string (COM_QUERY) Yes Yes
Plugin API Yes Limited
Read/Write splitting for MySQL Replication Yes, with plugin No
Load Balancing Yes, with plugin No
Fail over Yes, with plugin No
Lazy connections Yes, with plugin No
Query caching Yes, with plugin No
Transparent query manipulations (E.g., auto-EXPLAIN or monitoring)

四:mysql字符集设置

字符设置必须用特定的函数来设置,而不能用query来处理

<?php

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

// Will NOT affect $mysqli->real_escape_string();
$mysqli->query("SET NAMES utf8");

// Will NOT affect $mysqli->real_escape_string();
$mysqli->query("SET CHARACTER SET utf8");

// But, this will affect $mysqli->real_escape_string();
$mysqli->set_charset('utf8');

// But, this will NOT affect it (utf-8 vs utf8) -- don't use dashes here
$mysqli->set_charset('utf-8');

?>

注意:

设置utf8编码时,不能用utf-8,而是utf8(因为在mysql中设置编码不能包含-)

NotePossible UTF-8 confusion

Because character set names in MySQL do not contain dashes, the string "utf8" is valid in MySQL to set the character set to UTF-8. The string "utf-8" is not valid, as using "utf-8" will fail to change the character set.

php分享十五:php的数据库操作的更多相关文章

  1. 第十五章 MySQL 数据库

    学习要点:1.Web 数据库概述2.MySQL 的操作3.MySQL 常用函数4.SQL 语句详解5.phpMyadmin 一.Web数据库概述 现在,我们已经熟悉了PHP 的基础知识,这是我们想暂时 ...

  2. 十分钟学会mysql数据库操作

    Part1:写在最前 MySQL安装的方式有三种: ①rpm包安装 ②二进制包安装 ③源码安装 这里我们推荐二进制包安装,无论从安装速度还是用于生产库安装环境来说,都是没问题的.现在生产库一般采用My ...

  3. 雷林鹏分享:CodeIgniter常用的数据库操作类

    在 CodeIgniter 中,使用数据库是非常频繁的事情.你可以使用框架自带的数据库类,就能便捷地进行数据库操作. 初始化数据库类 依据你的数据库配置载入并初始化数据库类: $this->lo ...

  4. 边记边学PHP-(十五)MySQL数据库基础操作2

    四.使用可视化工具创建数据库 尽管使用命令行感觉更像我们程序猿,可是我还是比較喜欢使用workbench来创建数据库. 首先打开workbench , 一个比較友好的界面就打开了,哈哈.我还是比較喜欢 ...

  5. php分享十五:php的命令行操作

    一:像命令行传参数方法: 1: 使用$argc $argv 用法: /usr/local/php/bin/php ./getopt.php 123  456 2:使用getopt函数() http:/ ...

  6. Oracle得知(十五):分布式数据库

    --分布式数据库的独立性:分布数据的独立性指用户不必关心数据怎样切割和存储,仅仅需关心他须要什么数据. --本地操作 SQL> sqlplus scott/tiger --远程操作 SQL> ...

  7. Linux 笔记 - 第十五章 MySQL 常用操作和 phpMyAdmin

    博客地址:http://www.moonxy.com 一.前言 前面几章介绍了 MySQL 的安装和简单的配置,只会这些还不够,作为 Linux 系统管理员,我们还需要掌握一些基本的操作,以满足日常管 ...

  8. Python之路【第二十五篇】:数据库之pymysql模块

    数据库进阶 一.pymysql模块 pymysql是Python中操作Mysql的模块,其使用的方法和py2的MySQLdb几乎相同. 二.pymysql模块安装 pip install pymysq ...

  9. uni-app开发经验分享十五: uni-app 蓝牙打印功能

    最近在做uni-app项目时,遇到了需要蓝牙打印文件的功能需要制作,在网上找到了一个教程,这里分享给大家. 引入tsc.js 简单得引入到自己所需要得页面中去,本次我们只要到了标签模式,他同时还有账单 ...

随机推荐

  1. 规避javascript多人开发函数重名问题

    命名空间 封闭空间 js模块化mvc(数据层.表现层.控制层) seajs 变量转换成对象的属性 对象化

  2. zip 文件下载函数封装

    代码: export default { /** * 下载文件 */ exportFile: (fileUrl) => { if (fileUrl) { let exportFrame = do ...

  3. 如何去掉browserLinkSignalR

    在使用vs开发时查看源代码可以发现最下面有以下代码,此段代码会一直请求网络,感觉不爽的可以这样去掉: <!-- Visual Studio Browser Link --> <scr ...

  4. excel如何快速更改表格边框的颜色

    1.当完成基本的表格设置之后,对颜色不甚满意,怎么办 2.重新给表格选择一种颜色,这里会出现一个“笔”形状的鼠标箭头,不用理睬她 3.再次给表格统一加边框即可(开始--边框--所有框线)

  5. python之模块配置文件ConfigParser(在python3中变化较大)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之模块ConfigParser(在python3中为configparser) #特别注意:py ...

  6. Quartz.NET开源作业调度框架系列(四):Plugin Job-转

    如果在Quartz.NET作业运行时我们想动态修改Job和Trigger的绑定关系,同时修改一些参数那么该怎么办呢?Quartz.NET提供了插件技术,可以通过在XML文件中对Job和Trigger的 ...

  7. WinForm中 事件 委托 多线程的应用【以一个下载进度条为例】

    第一步:首先我们创建一个winfor的项目 第二步:我们建一个窗体 在一个窗体里面 打开一个另外的窗体 另外的窗体有一个按钮 点击后就开始下载 下载完成后 在注册窗体上面 显示下载完成(达到在一个窗体 ...

  8. spring 自动装配 default-autowire=&quot;byName/byType&quot;

    <PRE class=html name="code">spring 自动装配 default-autowire="byName/byType"   ...

  9. ubuntu 连接windows远程桌面 &&rdesktop 退出全屏模式

    参考:http://www.asgone.net/ubuntu-connect-windows-remote-desktop/ 呵呵,使用上了ubuntu,怎么接连上我的服务器的远程桌面呢,找了找帮助 ...

  10. 实现iOS序列化与反序列化(runtime)

    一.变量声明 为便于下文讨论,提前创建父类Biology以及子类Person: Biology: @interface Biology : NSObject { NSInteger *_hairCou ...