php擴展MySQLi

mysqli擴展允許我們訪問mysql?4.1及以上版本提供的功能。?

mysqli擴展和持久化連接

mysqli擴展的持久化連接在PHP5.3中被引入。支持已經存在于PDO MYSQL 和ext/mysql中。持久化連接背后的思想是客戶端進程和數據庫之間的連接可以通過一個客戶端進程來保持重用, 而不是多次的創建和銷毀。這降低了每次需要創建一個新連接的開銷,未使用的連接被緩存起來并且準備隨時被重用。

不像mysql擴展,mysqli沒有提供一個特殊的方法用于打開持久化連接。需要打開一個持久化連接時,你必須在 連接時在主機名前增加p:。

使用持久化連接的問題在于它們可能在客戶端處于不可預知的狀態。比如,一個表鎖可能在客戶端意外終止之前被激活。 一個新的客戶端進程重用這個持久化連接就會”按照原樣”得到這個連接。這樣,一個新的客戶端進程 為了更好的使用持久化連接,就需要做任何可能的清理工作,這樣就增加了對程序員的負擔。

mysqli擴展的持久化連接提供了內建的清理處理代碼。mysqli?所做的清理工作包括:

立即學習PHP免費學習筆記(深入)”;

回滾活動的事務

關閉并且刪除臨時表

對表解鎖、

重置會話變量

關閉prepared語句(在PHP中經常發生)

關閉處理程序

釋放通過?GET_LOCK()獲得的鎖

這確保了從連接池返回的持久化連接在客戶端進程使用它之前處于干凈的狀態。

mysqli擴展通過自動的調用C-API函數mysql_change_user()?來完成這個清理工作。

自動清理的特性有優點也有缺點。優點是程序員不再需要擔心附加的清理代碼,因為它們會自動調用。然而缺點就是 代碼可能會潛在的慢一點,因為每次從連接池返回一個連接都需要執行這些清理代碼。

這個自動清理的代碼可以通過在編譯php時定義MYSQLI_NO_CHANGE_USER_ON_PCONNECT?來關閉。

mysqli擴展在使用Mysql Native Driver或Mysql Client Library(libmysql)時都支持持久化連接。

MySQLi類

代表PHP和Mysql數據庫之間的一個連接。

mysqli::$affected_rows?— Gets the number of affected rows in a previous MySQL operation

mysqli::autocommit?— 打開或關閉本次數據庫連接的自動命令提交事務模式

mysqli::begin_transaction?— Starts a transaction

mysqli::change_user?— Changes the user of the specified database connection

mysqli::character_set_name?— 返回當前數據庫連接的默認字符編碼

mysqli::$client_info?— Get MySQL client info

mysqli::$client_version?— Returns the MySQL client version as a string

mysqli::close?— 關閉先前打開的數據庫連接

mysqli::commit?— 提交一個事務

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?— 將調試信息輸出到日志

mysqli::errno?— 返回最近函數調用的錯誤代碼

mysqli::$error_list?— Returns a list of errors from the last command executed

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?— Get MySQL client info

mysqli_get_client_stats?— Returns client per-process statistics

mysqli_get_client_version?— Returns the MySQL client version as an integer

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?— 對數據庫執行一次查詢

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?— 執行一個mysql查詢

mysqli::reap_async_query?— Get result from async query

mysqli::refresh?— Refreshes

mysqli::release_savepoint?— Rolls back a transaction to the named savepoint

mysqli::rollback?— 回退當前事務

mysqli::rpl_query_type?— Returns RPL query type

mysqli::savepoint?— Set a named transaction savepoint

mysqli::select_db?— 選擇用于數據庫查詢的默認數據庫

mysqli::send_query?— 發送請求并返回結果

mysqli::set_charset?— 設置默認字符編碼

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?— 初始化一條語句并返回一個用于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?— 返回是否是線程安全的

mysqli::use_result?— Initiate a result set retrieval

mysqli::$warning_count?— Returns the number of warnings from the last query for the given link

MySQLi_STMT類

代表一個prepared語句。

mysqli_stmt::$affected_rows?— Returns the total number of rows changed, deleted, or inserted by the last executed statement

mysqli_stmt::attr_get?— Used to get the current value of a statement attribute

mysqli_stmt::attr_set?— Used to modify the behavior of a prepared statement

mysqli_stmt::bind_param?— Binds variables to a prepared statement as parameters

mysqli_stmt::bind_result?— Binds variables to a prepared statement for result storage

mysqli_stmt::close?— Closes a prepared statement

mysqli_stmt::data_seek?— Seeks to an arbitrary row in statement result set

mysqli_stmt::$errno?— Returns the error code for the most recent statement call

mysqli_stmt::$error_list?— Returns a list of errors from the last statement executed

mysqli_stmt::$error?— Returns a string description for last statement error

mysqli_stmt::execute?— Executes a prepared Query

mysqli_stmt::fetch?— Fetch results from a prepared statement into the bound variables

mysqli_stmt::$field_count?— Returns the number of field in the given statement

mysqli_stmt::free_result?— Frees stored result memory for the given statement handle

mysqli_stmt::get_result?— Gets a result set from a prepared statement

mysqli_stmt::get_warnings?— Get result of SHOW WARNINGS

mysqli_stmt::$insert_id?— Get the ID generated from the previous INSERT operation

mysqli_stmt::more_results?— Check if there are more query results from a multiple query

mysqli_stmt::next_result?— Reads the next result from a multiple query

mysqli_stmt::$num_rows?— Return the number of rows in statements result set

mysqli_stmt::$param_count?— Returns the number of parameter for the given statement

mysqli_stmt::prepare?— Prepare an SQL statement for execution

mysqli_stmt::reset?— Resets a prepared statement

mysqli_stmt::result_metadata?— Returns result set metadata from a prepared statement

mysqli_stmt::send_long_data?— Send data in blocks

mysqli_stmt::$sqlstate?— Returns SQLSTATE error from previous statement operation

mysqli_stmt::store_result?— Transfers a result set from a prepared statement

mysqli_result類

代表從一個數據庫查詢中獲取的結果集

mysqli_result::$current_field?— Get current field offset of a result pointer

mysqli_result::data_seek?— Adjusts the result pointer to an arbitrary row in the result

mysqli_result::fetch_all?— Fetches all result rows as an associative array, a numeric array, or both

mysqli_result::fetch_array?— Fetch a result row as an associative, a numeric array, or both

mysqli_result::fetch_assoc?— Fetch a result row as an associative array

mysqli_result::fetch_field_direct?— Fetch meta-data for a single field

mysqli_result::fetch_field?— Returns the next field in the result set

mysqli_result::fetch_fields?— Returns an array of objects representing the fields in a result set

mysqli_result::fetch_object?— Returns the current row of a result set as an object

mysqli_result::fetch_row?— Get a result row as an enumerated array

mysqli_result::$field_count?— Get the number of fields in a result

mysqli_result::field_seek?— Set result pointer to a specified field offset

mysqli_result::free?— Frees the memory associated with a result

mysqli_result::$lengths?— Returns the lengths of the columns of the current row in the result set

mysqli_result::$num_rows?— Gets the number of rows in a result

MySQLi_Driver類

MySQLi 驅動.

client_info

客戶端API頭版本(比如:(string)”5.1.49″)

client_version

客戶端版本(比如:(int)50149)

driver_version

Mysqli驅動版本(比如:(int)101009)

embedded

是否開啟了MySQLi嵌入式支持。

reconnect

允許或阻止重連接(查看INI指令中的mysqli.reconnect)

report_mode

設置為MYSQLI_REPORT_OFF,?MYSQLI_REPORT_ALL或者?MYSQLI_REPORT_STRICT?(為錯誤拋出異常,譯注:需要和MYSQLI_REPORT_ERROR聯合使用),?MYSQLI_REPORT_ERROR?(報告MYSQL錯誤)和?MYSQLI_REPORT_INDEX?(報告索引相關的錯誤)的任意組合。

mysqli_driver::embedded_server_end?— Stop embedded server

mysqli_driver::embedded_server_start?— Initialize and start embedded server

mysqli_driver::$report_mode?— Enables or disables internal report functions

MySQLi_Warning類

代表一個Mysql警告。

message

消息字符串

sqlstate

SQL狀態

errno

錯誤編號

mysqli_warning::__construct?— The __construct purpose

mysqli_warning::next?— The next purpose

mysqli_sql_exception類

mysqli異常處理類

mysqli_sql_exception?extends?RuntimeException?{  ????/*?屬性?*/  ????protected?string?$sqlstate?;  ????/*?繼承的屬性?*/  ????protected?string?$message?;  ????protected?int?$code?;  ????protected?string?$file?;  ????protected?int?$line?;  }

別名和過時的Mysqli 函數

mysqli_bind_param?— mysqli_stmt_bind_param的別名

mysqli_bind_result?— mysqli_stmt_bind_result的別名

mysqli_client_encoding?— mysqli_character_set_name的別名

mysqli_connect?— 別名 mysqli::__construct

mysqli::disable_reads_from_master?— Disable reads from master

mysqli_disable_rpl_parse?— 禁用RPL解析

mysqli_enable_reads_from_master?— 開啟從主機讀取

mysqli_enable_rpl_parse?— 開啟RPL解析

mysqli_escape_string?— 別名 mysqli_real_escape_string

mysqli_execute?— mysqli_stmt_execute的別名

mysqli_fetch?— mysqli_stmt_fetch的別名。

mysqli_get_cache_stats?— 返回客戶端Zval緩存統計信息

mysqli_get_metadata?— mysqli_stmt_result_metadata的別名

mysqli_master_query?— 在主/從機制中強制在主機中執行一個查詢

mysqli_param_count?— mysqli_stmt_param_count的別名

mysqli_report?— 開啟或禁用(Mysql)內部(錯誤)報告函數

mysqli_rpl_parse_enabled?— 檢查是否開啟了RPL解析

mysqli_rpl_probe?— RPL探測

mysqli_send_long_data?— mysqli_stmt_send_long_data的別名

mysqli_set_opt?— mysqli_options的別名

mysqli_slave_query?— 在主/從機制中強制在從機上執行一個查詢

? 版權聲明
THE END
喜歡就支持一下吧
點贊7 分享