您好,欢迎访问一九零五行业门户网

php连接mysql数据库用到的三种API_MySQL

参考自php手册。本文没有太大意义,仅为方便自己上网查阅。
1、php的mysql扩展
2、php的mysqli扩展
3、php数据对象(pdo)
mysql扩展函数
       这是设计开发允许php应用与mysql数据库交互的早期扩展。mysql扩展提供了一个面向过程  的接口,并且是针对mysql4.1.3或更早版本设计的。因此,这个扩展虽然可以与mysql4.1.3或更新的数据库服务端  进行交互,但并不支持后期mysql服务端提供的一些特性。
mysql_affected_rows — 取得前一次 mysql 操作所影响的记录行数 mysql_client_encoding — 返回字符集的名称 mysql_close — 关闭 mysql 连接 mysql_connect — 打开一个到 mysql 服务器的连接 mysql_create_db — 新建一个 mysql 数据库 mysql_data_seek — 移动内部结果的指针 mysql_db_name — 取得结果数据 mysql_db_query — 发送一条 mysql 查询 mysql_drop_db — 丢弃(删除)一个 mysql 数据库 mysql_errno — 返回上一个 mysql 操作中的错误信息的数字编码 mysql_error — 返回上一个 mysql 操作产生的文本错误信息 mysql_escape_string — 转义一个字符串用于 mysql_query mysql_fetch_array — 从结果集中取得一行作为关联数组,或数字数组,或二者兼有 mysql_fetch_assoc — 从结果集中取得一行作为关联数组 mysql_fetch_field — 从结果集中取得列信息并作为对象返回 mysql_fetch_lengths — 取得结果集中每个输出的长度 mysql_fetch_object — 从结果集中取得一行作为对象 mysql_fetch_row — 从结果集中取得一行作为枚举数组 mysql_field_flags — 从结果中取得和指定字段关联的标志 mysql_field_len — 返回指定字段的长度 mysql_field_name — 取得结果中指定字段的字段名 mysql_field_seek — 将结果集中的指针设定为制定的字段偏移量 mysql_field_table — 取得指定字段所在的表名 mysql_field_type — 取得结果集中指定字段的类型 mysql_free_result — 释放结果内存 mysql_get_client_info — 取得 mysql 客户端信息 mysql_get_host_info — 取得 mysql 主机信息 mysql_get_proto_info — 取得 mysql 协议信息 mysql_get_server_info — 取得 mysql 服务器信息 mysql_info — 取得最近一条查询的信息 mysql_insert_id — 取得上一步 insert 操作产生的 id mysql_list_dbs — 列出 mysql 服务器中所有的数据库 mysql_list_fields — 列出 mysql 结果中的字段 mysql_list_processes — 列出 mysql 进程 mysql_list_tables — 列出 mysql 数据库中的表 mysql_num_fields — 取得结果集中字段的数目 mysql_num_rows — 取得结果集中行的数目 mysql_pconnect — 打开一个到 mysql 服务器的持久连接 mysql_ping — ping 一个服务器连接,如果没有连接则重新连接 mysql_query — 发送一条 mysql 查询 mysql_real_escape_string — 转义 sql 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集 mysql_result — 取得结果数据 mysql_select_db — 选择 mysql 数据库 mysql_set_charset — sets the client character set mysql_stat — 取得当前系统状态 mysql_tablename — 取得表名 mysql_thread_id — 返回当前线程的 id mysql_unbuffered_query — 向 mysql 发送一条 sql 查询,并不获取和缓存结果的行
php的mysqli扩展
      mysqli扩展,我们有时称之为mysql增强扩展,可以用于使用   mysql4.1.3或更新版本中新的高级特性。mysqli扩展在php 5及以后版本中包含。
面向对象接口
      prepared语句支持
      多语句执行支持
     事务支持
     增强的调试能力
     嵌入式服务支持
     如果你使用mysql4.1.3或更新版本,强烈建议你使用这个扩展。
     mysqli           {
/* 属性 */
int $mysqli->affected_rows;
string $client_info;
int $client_version;
string $connect_errno;
string $connect_error;
int $errno;
string $error;
int $field_count;
int $client_version;
string $host_info;
string $protocol_version;
string $server_info;
int $server_version;
string $info;
mixed $insert_id;
string $sqlstate;
int $thread_id;
int $warning_count;
/* 方法 */
int mysqli_affected_rows    ( mysqli$link   )
bool mysqli::autocommit    ( bool$mode   )
bool mysqli::change_user    ( string$user   , string$password   , string$database   )
string mysqli::character_set_name    ( void   )
string mysqli_get_client_info    ( mysqli$link   )
int mysqli_get_client_version    ( mysqli$link   )
bool mysqli::close    ( void   )
bool mysqli::commit    ( void   )
int mysqli_connect_errno    ( void   )
string mysqli_connect_error    ( void   )
mysqli mysqli_connect    ([ 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)  ]]]]]] )
bool mysqli::debug    ( string$message   )
bool mysqli::dump_debug_info    ( void   )
int mysqli_errno    ( mysqli$link   )
string mysqli_error    ( mysqli$link   )
int mysqli_field_count    ( mysqli$link   )
object mysqli::get_charset    ( void   )
string mysqli::get_client_info    ( void   )
array mysqli_get_client_stats    ( void   )
int mysqli_get_client_version    ( mysqli$link   )
bool mysqli::get_connection_stats    ( void   )
string mysqli_get_host_info    ( mysqli$link   )
int mysqli_get_proto_info    ( mysqli$link   )
string mysqli_get_server_info    ( mysqli$link   )
int mysqli_get_server_version    ( mysqli$link   )
mysqli_warning mysqli::get_warnings    ( void   )
string mysqli_info    ( mysqli$link   )
mysqli mysqli::init    ( void   )
mixed mysqli_insert_id    ( mysqli$link   )
bool mysqli::kill    ( int $processid   )
bool mysqli::more_results    ( void   )
bool mysqli::multi_query    ( string$query   )
bool mysqli::next_result    ( void   )
bool mysqli::options    ( int$option   , mixed$value   )
bool mysqli::ping    ( void   )
public int mysqli::poll    ( array &$read   , array&$error   , array&$reject   , int $sec   [, int $usec  ] )
mysqli_stmt mysqli::prepare    ( string$query   )
mixed mysqli::query    ( string$query   [, int$resultmode  ] )
bool mysqli::real_connect    ([ string$host   [, string$username   [, string$passwd   [, string$dbname   [, int$port   [, string$socket   [, int$flags  ]]]]]]] )
string mysqli::escape_string    ( string$escapestr   )
bool mysqli::real_query      ( string$query    )
public mysqli_result mysqli::reap_async_query    ( void   )
bool mysqli::rollback    ( void   )
bool mysqli::select_db    ( string$dbname   )
bool mysqli::set_charset    ( string$charset   )
void mysqli_set_local_infile_default    ( mysqli$link   )
bool mysqli::set_local_infile_handler    ( mysqli$link   , callback$read_func   )
string mysqli_sqlstate    ( mysqli$link   )
bool mysqli::ssl_set    ( string$key   , string$cert   , string$ca   , string$capath   , string$cipher   )
string mysqli::stat    ( void   )
mysqli_stmt mysqli::stmt_init    ( void   )
mysqli_result mysqli::store_result    ( void   )
int mysqli_thread_id    ( mysqli$link   )
bool mysqli_thread_safe    ( void   )
mysqli_result mysqli::use_result    ( void   )
int mysqli_warning_count    ( mysqli$link   )
   }
table of contents
mysqli->affected_rows — gets the number of affected rows in a previous mysql operation mysqli::autocommit — turns on or off auto-commiting database modifications mysqli::change_user — changes the user of the specified database connection mysqli::character_set_name — returns the default character set for the database connection mysqli->client_info — returns the mysql client version as a string mysqli->client_version — get mysql client info mysqli::close — closes a previously opened database connection mysqli::commit — commits the current transaction mysqli->connect_errno — returns the error code from last connect call mysqli->connect_error — returns a string description of the last connect error mysqli::__construct — open a new connection to the mysql server mysqli::debug — performs debugging operations mysqli::dump_debug_info — dump debugging information into the log mysqli->errno — returns the error code for the most recent function call mysqli->error — returns a string description of the last error mysqli->field_count — returns the number of columns for the most recent query mysqli::get_charset — returns a character set object mysqli->get_client_info — returns the mysql client version as a string mysqli_get_client_stats — returns client per-process statistics mysqli->client_version — get mysql client info mysqli::get_connection_stats — returns statistics about the client connection mysqli->host_info — returns a string representing the type of connection used mysqli->protocol_version — returns the version of the mysql protocol used mysqli->server_info — returns the version of the mysql server mysqli->server_version — returns the version of the mysql server as an integer mysqli::get_warnings — get result of show warnings mysqli->info — retrieves information about the most recently executed query mysqli::init — initializes mysqli and returns a resource for use with mysqli_real_connect() mysqli->insert_id — returns the auto generated id used in the last query mysqli::kill — asks the server to kill a mysql thread mysqli::more_results — check if there are any more query results from a multi query mysqli::multi_query — performs a query on the database mysqli::next_result — prepare next result from multi_query mysqli::options — set options mysqli::ping — pings a server connection, or tries to reconnect if the connection has gone down mysqli::poll — poll connections mysqli::prepare — prepare an sql statement for execution mysqli::query — performs a query on the database mysqli::real_connect — opens a connection to a mysql server mysqli::real_escape_string — escapes special characters in a string for use in an sql statement, taking into account the current charset of the connection mysqli::real_query — execute an sql query mysqli::reap_async_query — get result from async query mysqli::rollback — rolls back current transaction mysqli::select_db — selects the default database for database queries mysqli::set_charset — sets the default client character set mysqli::set_local_infile_default — unsets user defined handler for load local infile command mysqli::set_local_infile_handler — set callback function for load data local infile command mysqli->sqlstate — returns the sqlstate error from previous mysql operation mysqli::ssl_set — used for establishing secure connections using ssl mysqli::stat — gets the current system status mysqli::stmt_init — initializes a statement and returns an object for use with mysqli_stmt_prepare mysqli::store_result — transfers a result set from the last query mysqli->thread_id — returns the thread id for the current connection mysqli::thread_safe — returns whether thread safety is given or not mysqli::use_result — initiate a result set retrieval mysqli->warning_count — returns the number of warnings from the last query for the given link
php数据对象(pdo)
      php数据对象,是php应用中的一个数据库抽象层规范。pdo提供了一个统一的api接口可以使得你的php应用不去关心具体要  连接的数据库服务器系统类型。也就是说,如果你使用pdo的api,可以在任何需要的时候无缝切换数据库服务器,比如从firebird   到mysql,仅仅需要修改很少的php代码。
     当然,pdo也有它自己的先进性,比如一个干净的,简单的,可移植的api,它最主要的缺点是会限制让你不能使用  后期mysql服务端提供所有的数据库高级特性。比如,pdo不允许使用mysql支持的多语句执行。
     pdo的mysql驱动并不是一套api,至少从php程序员的角度来看是这样的。实际上,pdo的mysql驱动处于pdo自己的下层,  提供了特定的mysql功能。程序员直接调用pdo的api,而pdo使用了pdo的mysql驱动完成与mysql服务器端的交互。  
     pdo的mysql驱动是众多pdo驱动中的一个。其他可用的pdo驱动包括firebird,postgresql等等。
pdo           {
__construct    ( string$dsn   [, string$username   [, string$password   [, array$driver_options  ]]] )
bool begintransaction    ( void   )
bool commit    ( void   )
mixed errorcode    ( void   )
array errorinfo    ( void   )
int exec    ( string $statement   )
mixed getattribute    ( int $attribute   )
array getavailabledrivers    ( void   )
bool intransaction    ( void   )
string lastinsertid    ([ string$name =null  ] )
pdostatement prepare    ( string$statement   [, array$driver_options = array()  ] )
pdostatement query    ( string$statement   )
string quote    ( string $string   [, int $parameter_type = pdo::param_str  ] )
bool rollback    ( void   )
bool setattribute    ( int $attribute   , mixed$value   )
    }
table of contents
pdo::begintransaction — initiates a transaction pdo::commit — commits a transaction pdo::__construct — creates a pdo instance representing a connection to a database pdo::errorcode — fetch the sqlstate associated with the last operation on the database handle pdo::errorinfo — fetch extended error information associated with the last operation on the database handle pdo::exec — execute an sql statement and return the number of affected rows pdo::getattribute — retrieve a database connection attribute pdo::getavailabledrivers — return an array of available pdo drivers pdo::intransaction — checks if inside a transaction pdo::lastinsertid — returns the id of the last inserted row or sequence value pdo::prepare — prepares a statement for execution and returns a statement object pdo::query — executes an sql statement, returning a result set as a pdostatement object pdo::quote — quotes a string for use in a query. pdo::rollback — rolls back a transaction pdo::setattribute — set an attribute
其它类似信息

推荐信息