一:术语解释:

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. map集合中value()、keySet()、entrySet()区别

    在Map集合中 values():方法是获取集合中的所有的值----没有键,没有对应关系, KeySet():将Map中所有的键存入到set集合中.因为set具备迭代器.所有可以迭代方式取出所有的键, ...

  2. 官方sakila测试库

    官方sakila测试库 http://downloads.mysql.com/docs/sakila-db.zip

  3. django之创建第9个项目-管理后台admin

    django之创建第9个项目-管理后台admin配置 1.配置setting文件INSTALLED_APPS = (    'django.contrib.auth',    'django.cont ...

  4. redis配置笔记

    #cd /opt#tar -zxvf redis-4.0.6.tar.gz#cd redis-4.0.6#make #cd src#make install PREFIX=/usr/local/red ...

  5. (原)torch模型转pytorch模型

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/7839263.html 目前使用的torch模型转pytorch模型的程序为: https://gith ...

  6. Swift打印Debug日志,实现Release下不打印

    OC内,我们往往做log打印时,会考虑一个Debug环境下打印,Release下控制不打印,以节约性能消耗. OC我们可以这样做: 在pch文件内,定义如下: //打印日志 #ifdef DEBUG ...

  7. Learning to Rank:Point-wise、Pair-wise 和 List-wise区别

    机器学习的 ranking 技术——learning2rank,包括 pointwise.pairwise.listwise 三大类型. [Ref-1]给出的: <Point wise rank ...

  8. Lua初学

    Lua很火啊,而且跟C,c++可以无缝结合,表示很给力,算是我的第三门语言吧,哈哈! 在官网上下载了源码了,和windows版的,表示编译器也很给力,直接可以用SciTE就可以写代码了. a = 1; ...

  9. 【LeetCode】210. Course Schedule II

    Course Schedule II There are a total of n courses you have to take, labeled from 0 to n - 1. Some co ...

  10. Android 桌面部件

    桌面部件是一种利用AppWidget框架将应用程序的某个部件放在桌面. res/layout/digitalclock.xml <?xml version="1.0" enc ...