PHP數據庫擴展之MySQL增強版擴展MySQLi
mysqli擴展允許我們訪問MySQL 4.1及以上版本提供的功能。?
mysqli擴展和持久化連接mysqli擴展的持久化連接在PHP5.3中被引入。支持已經存在于PDO MYSQL 和ext/mysql中。持久化連接背后的思想是客戶端進程和數據庫之間的連接可以通過一個客戶端進程來保持重用, 而不是多次的創建和銷毀。這降低了每次需要創建一個新連接的開銷,未使用的連接被緩存起來并且準備隨時被重用。
不像mysql擴展,mysqli沒有提供一個特殊的方法用于打開持久化連接。需要打開一個持久化連接時,你必須在 連接時在主機名前增加p:。
使用持久化連接的問題在于它們可能在客戶端處于不可預知的狀態。比如,一個表鎖可能在客戶端意外終止之前被激活。 一個新的客戶端進程重用這個持久化連接就會'按照原樣'得到這個連接。這樣,一個新的客戶端進程 為了更好的使用持久化連接,就需要做任何可能的清理工作,這樣就增加了對程序員的負擔。
mysqli擴展的持久化連接提供了內建的清理處理代碼。mysqli?所做的清理工作包括:
回滾活動的事務關閉并且刪除臨時表對表解鎖、重置會話變量關閉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 operationmysqli::autocommit?— 打開或關閉本次數據庫連接的自動命令提交事務模式mysqli::begin_transaction?— Starts a transactionmysqli::change_user?— Changes the user of the specified database connectionmysqli::character_set_name?— 返回當前數據庫連接的默認字符編碼mysqli::$client_info?— Get MySQL client infomysqli::$client_version?— Returns the MySQL client version as a stringmysqli::close?— 關閉先前打開的數據庫連接mysqli::commit?— 提交一個事務mysqli::$connect_errno?— Returns the error code from last connect callmysqli::$connect_error?— Returns a string description of the last connect errormysqli::__construct?— Open a new connection to the MySQL servermysqli::debug?— Performs debugging operationsmysqli::dump_debug_info?— 將調試信息輸出到日志mysqli::errno?— 返回最近函數調用的錯誤代碼mysqli::$error_list?— Returns a list of errors from the last command executedmysqli::$error?— Returns a string description of the last errormysqli::$field_count?— Returns the number of columns for the most recent querymysqli::get_charset?— Returns a character set objectmysqli::get_client_info?— Get MySQL client infomysqli_get_client_stats?— Returns client per-process statisticsmysqli_get_client_version?— Returns the MySQL client version as an integermysqli::get_connection_stats?— Returns statistics about the client connectionmysqli::$host_info?— Returns a string representing the type of connection usedmysqli::$protocol_version?— Returns the version of the MySQL protocol usedmysqli::$server_info?— Returns the version of the MySQL servermysqli::$server_version?— Returns the version of the MySQL server as an integermysqli::get_warnings?— Get result of SHOW WARNINGSmysqli::$info?— Retrieves information about the most recently executed querymysqli::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 querymysqli::kill?— Asks the server to kill a MySQL threadmysqli::more_results?— Check if there are any more query results from a multi querymysqli::multi_query?— Performs a query on the databasemysqli::next_result?— Prepare next result from multi_querymysqli::options?— Set optionsmysqli::ping?— Pings a server connection, or tries to reconnect if the connection has gone downmysqli::poll?— Poll connectionsmysqli::prepare?— Prepare an SQL statement for executionmysqli::query?— 對數據庫執行一次查詢mysqli::real_connect?— Opens a connection to a mysql servermysqli::real_escape_string?— Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connectionmysqli::real_query?— 執行一個mysql查詢mysqli::reap_async_query?— Get result from async querymysqli::refresh?— Refreshesmysqli::release_savepoint?— Rolls back a transaction to the named savepointmysqli::rollback?— 回退當前事務mysqli::rpl_query_type?— Returns RPL query typemysqli::savepoint?— Set a named transaction savepointmysqli::select_db?— 選擇用于數據庫查詢的默認數據庫mysqli::send_query?— 發送請求并返回結果mysqli::set_charset?— 設置默認字符編碼mysqli::set_local_infile_default?— Unsets user defined handler for load local infile commandmysqli::set_local_infile_handler?— Set callback function for LOAD DATA LOCAL INFILE commandmysqli::$sqlstate?— Returns the SQLSTATE error from previous MySQL operationmysqli::ssl_set?— Used for establishing secure connections using SSLmysqli::stat?— Gets the current system statusmysqli::stmt_init?— 初始化一條語句并返回一個用于mysqli_stmt_prepare(調用)的對象mysqli::store_result?— Transfers a result set from the last querymysqli::$thread_id?— Returns the thread ID for the current connectionmysqli::thread_safe?— 返回是否是線程安全的mysqli::use_result?— Initiate a result set retrievalmysqli::$warning_count?— Returns the number of warnings from the last query for the given linkMySQLi_STMT類代表一個prepared語句。
mysqli_stmt::$affected_rows?— Returns the total number of rows changed, deleted, or inserted by the last executed statementmysqli_stmt::attr_get?— Used to get the current value of a statement attributemysqli_stmt::attr_set?— Used to modify the behavior of a prepared statementmysqli_stmt::bind_param?— Binds variables to a prepared statement as parametersmysqli_stmt::bind_result?— Binds variables to a prepared statement for result storagemysqli_stmt::close?— Closes a prepared statementmysqli_stmt::data_seek?— Seeks to an arbitrary row in statement result setmysqli_stmt::$errno?— Returns the error code for the most recent statement callmysqli_stmt::$error_list?— Returns a list of errors from the last statement executedmysqli_stmt::$error?— Returns a string description for last statement errormysqli_stmt::execute?— Executes a prepared Querymysqli_stmt::fetch?— Fetch results from a prepared statement into the bound variablesmysqli_stmt::$field_count?— Returns the number of field in the given statementmysqli_stmt::free_result?— Frees stored result memory for the given statement handlemysqli_stmt::get_result?— Gets a result set from a prepared statementmysqli_stmt::get_warnings?— Get result of SHOW WARNINGSmysqli_stmt::$insert_id?— Get the ID generated from the previous INSERT operationmysqli_stmt::more_results?— Check if there are more query results from a multiple querymysqli_stmt::next_result?— Reads the next result from a multiple querymysqli_stmt::$num_rows?— Return the number of rows in statements result setmysqli_stmt::$param_count?— Returns the number of parameter for the given statementmysqli_stmt::prepare?— Prepare an SQL statement for executionmysqli_stmt::reset?— Resets a prepared statementmysqli_stmt::result_metadata?— Returns result set metadata from a prepared statementmysqli_stmt::send_long_data?— Send data in blocksmysqli_stmt::$sqlstate?— Returns SQLSTATE error from previous statement operationmysqli_stmt::store_result?— Transfers a result set from a prepared statementmysqli_result類代表從一個數據庫查詢中獲取的結果集
mysqli_result::$current_field?— Get current field offset of a result pointermysqli_result::data_seek?— Adjusts the result pointer to an arbitrary row in the resultmysqli_result::fetch_all?— Fetches all result rows as an associative array, a numeric array, or bothmysqli_result::fetch_array?— Fetch a result row as an associative, a numeric array, or bothmysqli_result::fetch_assoc?— Fetch a result row as an associative arraymysqli_result::fetch_field_direct?— Fetch meta-data for a single fieldmysqli_result::fetch_field?— Returns the next field in the result setmysqli_result::fetch_fields?— Returns an array of objects representing the fields in a result setmysqli_result::fetch_object?— Returns the current row of a result set as an objectmysqli_result::fetch_row?— Get a result row as an enumerated arraymysqli_result::$field_count?— Get the number of fields in a resultmysqli_result::field_seek?— Set result pointer to a specified field offsetmysqli_result::free?— Frees the memory associated with a resultmysqli_result::$lengths?— Returns the lengths of the columns of the current row in the result setmysqli_result::$num_rows?— Gets the number of rows in a resultMySQLi_Driver類MySQLi 驅動.
client_info客戶端API頭版本(比如:(string)'5.1.49')client_version客戶端版本(比如:(int)50149)driver_versionMysqli驅動版本(比如:(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 servermysqli_driver::embedded_server_start?— Initialize and start embedded servermysqli_driver::$report_mode?— Enables or disables internal report functionsMySQLi_Warning類代表一個Mysql警告。
message消息字符串sqlstateSQL狀態errno錯誤編號mysqli_warning::__construct?— The __construct purposemysqli_warning::next?— The next purposemysqli_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::__constructmysqli::disable_reads_from_master?— Disable reads from mastermysqli_disable_rpl_parse?— 禁用RPL解析mysqli_enable_reads_from_master?— 開啟從主機讀取mysqli_enable_rpl_parse?— 開啟RPL解析mysqli_escape_string?— 別名 mysqli_real_escape_stringmysqli_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?— 在主/從機制中強制在從機上執行一個查詢
相關文章:
