php调mysql接口头文件_php基础系列:PHP连接MySQL数据库用到的三种API
參考自php手冊(cè)。本文沒有太大意義,僅為方便自己上網(wǎng)查閱。
1、PHP的MySQL擴(kuò)展
2、PHP的mysqli擴(kuò)展
3、PHP數(shù)據(jù)對(duì)象(PDO)
MySQL擴(kuò)展函數(shù)
這是設(shè)計(jì)開發(fā)允許PHP應(yīng)用與MySQL數(shù)據(jù)庫(kù)交互的早期擴(kuò)展。mysql擴(kuò)展提供了一個(gè)面向過(guò)程 的接口,并且是針對(duì)MySQL4.1.3或更早版本設(shè)計(jì)的。因此,這個(gè)擴(kuò)展雖然可以與MySQL4.1.3或更新的數(shù)據(jù)庫(kù)服務(wù)端 進(jìn)行交互,但并不支持后期MySQL服務(wù)端提供的一些特性。
mysql_affected_rows — 取得前一次 MySQL 操作所影響的記錄行數(shù)
mysql_client_encoding — 返回字符集的名稱
mysql_close — 關(guān)閉 MySQL 連接
mysql_connect — 打開一個(gè)到 MySQL 服務(wù)器的連接
mysql_create_db — 新建一個(gè) MySQL 數(shù)據(jù)庫(kù)
mysql_data_seek — 移動(dòng)內(nèi)部結(jié)果的指針
mysql_db_name — 取得結(jié)果數(shù)據(jù)
mysql_db_query — 發(fā)送一條 MySQL 查詢
mysql_drop_db — 丟棄(刪除)一個(gè) MySQL 數(shù)據(jù)庫(kù)
mysql_errno — 返回上一個(gè) MySQL 操作中的錯(cuò)誤信息的數(shù)字編碼
mysql_error — 返回上一個(gè) MySQL 操作產(chǎn)生的文本錯(cuò)誤信息
mysql_escape_string — 轉(zhuǎn)義一個(gè)字符串用于 mysql_query
mysql_fetch_array — 從結(jié)果集中取得一行作為關(guān)聯(lián)數(shù)組,或數(shù)字?jǐn)?shù)組,或二者兼有
mysql_fetch_assoc — 從結(jié)果集中取得一行作為關(guān)聯(lián)數(shù)組
mysql_fetch_field — 從結(jié)果集中取得列信息并作為對(duì)象返回
mysql_fetch_lengths — 取得結(jié)果集中每個(gè)輸出的長(zhǎng)度
mysql_fetch_object — 從結(jié)果集中取得一行作為對(duì)象
mysql_fetch_row — 從結(jié)果集中取得一行作為枚舉數(shù)組
mysql_field_flags — 從結(jié)果中取得和指定字段關(guān)聯(lián)的標(biāo)志
mysql_field_len — 返回指定字段的長(zhǎng)度
mysql_field_name — 取得結(jié)果中指定字段的字段名
mysql_field_seek — 將結(jié)果集中的指針設(shè)定為制定的字段偏移量
mysql_field_table — 取得指定字段所在的表名
mysql_field_type — 取得結(jié)果集中指定字段的類型
mysql_free_result — 釋放結(jié)果內(nèi)存
mysql_get_client_info — 取得 MySQL 客戶端信息
mysql_get_host_info — 取得 MySQL 主機(jī)信息
mysql_get_proto_info — 取得 MySQL 協(xié)議信息
mysql_get_server_info — 取得 MySQL 服務(wù)器信息
mysql_info — 取得最近一條查詢的信息
mysql_insert_id — 取得上一步 INSERT 操作產(chǎn)生的 ID
mysql_list_dbs — 列出 MySQL 服務(wù)器中所有的數(shù)據(jù)庫(kù)
mysql_list_fields — 列出 MySQL 結(jié)果中的字段
mysql_list_processes — 列出 MySQL 進(jìn)程
mysql_list_tables — 列出 MySQL 數(shù)據(jù)庫(kù)中的表
mysql_num_fields — 取得結(jié)果集中字段的數(shù)目
mysql_num_rows — 取得結(jié)果集中行的數(shù)目
mysql_pconnect — 打開一個(gè)到 MySQL 服務(wù)器的持久連接
mysql_ping — Ping 一個(gè)服務(wù)器連接,如果沒有連接則重新連接
mysql_query — 發(fā)送一條 MySQL 查詢
mysql_real_escape_string — 轉(zhuǎn)義 SQL 語(yǔ)句中使用的字符串中的特殊字符,并考慮到連接的當(dāng)前字符集
mysql_result — 取得結(jié)果數(shù)據(jù)
mysql_select_db — 選擇 MySQL 數(shù)據(jù)庫(kù)
mysql_set_charset — Sets the client character set
mysql_stat — 取得當(dāng)前系統(tǒng)狀態(tài)
mysql_tablename — 取得表名
mysql_thread_id — 返回當(dāng)前線程的 ID
mysql_unbuffered_query — 向 MySQL 發(fā)送一條 SQL 查詢,并不獲取和緩存結(jié)果的行
PHP的mysqli擴(kuò)展
mysqli擴(kuò)展,我們有時(shí)稱之為MySQL增強(qiáng)擴(kuò)展,可以用于使用 MySQL4.1.3或更新版本中新的高級(jí)特性。mysqli擴(kuò)展在PHP 5及以后版本中包含。
面向?qū)ο蠼涌?/p>
prepared語(yǔ)句支持
多語(yǔ)句執(zhí)行支持
事務(wù)支持
增強(qiáng)的調(diào)試能力
嵌入式服務(wù)支持
如果你使用MySQL4.1.3或更新版本,強(qiáng)烈建議你使用這個(gè)擴(kuò)展。
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_warningmysqli::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_resultmysqli::store_result (void )
int mysqli_thread_id ( mysqli$link )
bool mysqli_thread_safe ( void )
mysqli_resultmysqli::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數(shù)據(jù)對(duì)象(PDO)
PHP數(shù)據(jù)對(duì)象,是PHP應(yīng)用中的一個(gè)數(shù)據(jù)庫(kù)抽象層規(guī)范。PDO提供了一個(gè)統(tǒng)一的API接口可以使得你的PHP應(yīng)用不去關(guān)心具體要 連接的數(shù)據(jù)庫(kù)服務(wù)器系統(tǒng)類型。也就是說(shuō),如果你使用PDO的API,可以在任何需要的時(shí)候無(wú)縫切換數(shù)據(jù)庫(kù)服務(wù)器,比如從Firebird 到MySQL,僅僅需要修改很少的PHP代碼。
當(dāng)然,PDO也有它自己的先進(jìn)性,比如一個(gè)干凈的,簡(jiǎn)單的,可移植的API,它最主要的缺點(diǎn)是會(huì)限制讓你不能使用 后期MySQL服務(wù)端提供所有的數(shù)據(jù)庫(kù)高級(jí)特性。比如,PDO不允許使用MySQL支持的多語(yǔ)句執(zhí)行。
PDO的MySQL驅(qū)動(dòng)并不是一套API,至少?gòu)腜HP程序員的角度來(lái)看是這樣的。實(shí)際上,PDO的MySQL驅(qū)動(dòng)處于PDO自己的下層, 提供了特定的Mysql功能。程序員直接調(diào)用PDO的API,而PDO使用了PDO的MySQL驅(qū)動(dòng)完成與MySQL服務(wù)器端的交互。
PDO的MySQL驅(qū)動(dòng)是眾多PDO驅(qū)動(dòng)中的一個(gè)。其他可用的PDO驅(qū)動(dòng)包括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 ] )
PDOStatementprepare (string$statement [,array$driver_options = array() ] )
PDOStatementquery (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
總結(jié)
以上是生活随笔為你收集整理的php调mysql接口头文件_php基础系列:PHP连接MySQL数据库用到的三种API的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 如何练习后空翻
- 下一篇: linux cmake编译源码,linu