PHP數(shù)據(jù)庫(kù)擴(kuò)展之MySQL增強(qiáng)版擴(kuò)展MySQLi
mysqli擴(kuò)展允許我們?cè)L問(wèn)MySQL 4.1及以上版本提供的功能。?
mysqli擴(kuò)展和持久化連接mysqli擴(kuò)展的持久化連接在PHP5.3中被引入。支持已經(jīng)存在于PDO MYSQL 和ext/mysql中。持久化連接背后的思想是客戶端進(jìn)程和數(shù)據(jù)庫(kù)之間的連接可以通過(guò)一個(gè)客戶端進(jìn)程來(lái)保持重用, 而不是多次的創(chuàng)建和銷毀。這降低了每次需要?jiǎng)?chuàng)建一個(gè)新連接的開(kāi)銷,未使用的連接被緩存起來(lái)并且準(zhǔn)備隨時(shí)被重用。
不像mysql擴(kuò)展,mysqli沒(méi)有提供一個(gè)特殊的方法用于打開(kāi)持久化連接。需要打開(kāi)一個(gè)持久化連接時(shí),你必須在 連接時(shí)在主機(jī)名前增加p:。
使用持久化連接的問(wèn)題在于它們可能在客戶端處于不可預(yù)知的狀態(tài)。比如,一個(gè)表鎖可能在客戶端意外終止之前被激活。 一個(gè)新的客戶端進(jìn)程重用這個(gè)持久化連接就會(huì)'按照原樣'得到這個(gè)連接。這樣,一個(gè)新的客戶端進(jìn)程 為了更好的使用持久化連接,就需要做任何可能的清理工作,這樣就增加了對(duì)程序員的負(fù)擔(dān)。
mysqli擴(kuò)展的持久化連接提供了內(nèi)建的清理處理代碼。mysqli?所做的清理工作包括:
回滾活動(dòng)的事務(wù)關(guān)閉并且刪除臨時(shí)表對(duì)表解鎖、重置會(huì)話變量關(guān)閉prepared語(yǔ)句(在PHP中經(jīng)常發(fā)生)關(guān)閉處理程序釋放通過(guò)?GET_LOCK()獲得的鎖這確保了從連接池返回的持久化連接在客戶端進(jìn)程使用它之前處于干凈的狀態(tài)。
mysqli擴(kuò)展通過(guò)自動(dòng)的調(diào)用C-API函數(shù)mysql_change_user()?來(lái)完成這個(gè)清理工作。
自動(dòng)清理的特性有優(yōu)點(diǎn)也有缺點(diǎn)。優(yōu)點(diǎn)是程序員不再需要擔(dān)心附加的清理代碼,因?yàn)樗鼈儠?huì)自動(dòng)調(diào)用。然而缺點(diǎn)就是 代碼可能會(huì)潛在的慢一點(diǎn),因?yàn)槊看螐倪B接池返回一個(gè)連接都需要執(zhí)行這些清理代碼。
這個(gè)自動(dòng)清理的代碼可以通過(guò)在編譯php時(shí)定義MYSQLI_NO_CHANGE_USER_ON_PCONNECT?來(lái)關(guān)閉。
mysqli擴(kuò)展在使用Mysql Native Driver或Mysql Client Library(libmysql)時(shí)都支持持久化連接。
MySQLi類代表PHP和Mysql數(shù)據(jù)庫(kù)之間的一個(gè)連接。
mysqli::$affected_rows?— Gets the number of affected rows in a previous MySQL operationmysqli::autocommit?— 打開(kāi)或關(guān)閉本次數(shù)據(jù)庫(kù)連接的自動(dòng)命令提交事務(wù)模式mysqli::begin_transaction?— Starts a transactionmysqli::change_user?— Changes the user of the specified database connectionmysqli::character_set_name?— 返回當(dāng)前數(shù)據(jù)庫(kù)連接的默認(rèn)字符編碼mysqli::$client_info?— Get MySQL client infomysqli::$client_version?— Returns the MySQL client version as a stringmysqli::close?— 關(guān)閉先前打開(kāi)的數(shù)據(jù)庫(kù)連接mysqli::commit?— 提交一個(gè)事務(wù)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?— 將調(diào)試信息輸出到日志mysqli::errno?— 返回最近函數(shù)調(diào)用的錯(cuò)誤代碼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?— 對(duì)數(shù)據(jù)庫(kù)執(zhí)行一次查詢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?— 執(zhí)行一個(gè)mysql查詢mysqli::reap_async_query?— Get result from async querymysqli::refresh?— Refreshesmysqli::release_savepoint?— Rolls back a transaction to the named savepointmysqli::rollback?— 回退當(dāng)前事務(wù)mysqli::rpl_query_type?— Returns RPL query typemysqli::savepoint?— Set a named transaction savepointmysqli::select_db?— 選擇用于數(shù)據(jù)庫(kù)查詢的默認(rèn)數(shù)據(jù)庫(kù)mysqli::send_query?— 發(fā)送請(qǐng)求并返回結(jié)果mysqli::set_charset?— 設(shè)置默認(rèn)字符編碼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?— 初始化一條語(yǔ)句并返回一個(gè)用于mysqli_stmt_prepare(調(diào)用)的對(duì)象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類代表一個(gè)prepared語(yǔ)句。
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類代表從一個(gè)數(shù)據(jù)庫(kù)查詢中獲取的結(jié)果集
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 驅(qū)動(dòng).
client_info客戶端API頭版本(比如:(string)'5.1.49')client_version客戶端版本(比如:(int)50149)driver_versionMysqli驅(qū)動(dòng)版本(比如:(int)101009)embedded是否開(kāi)啟了MySQLi嵌入式支持。reconnect允許或阻止重連接(查看INI指令中的mysqli.reconnect)report_mode設(shè)置為MYSQLI_REPORT_OFF,?MYSQLI_REPORT_ALL或者?MYSQLI_REPORT_STRICT?(為錯(cuò)誤拋出異常,譯注:需要和MYSQLI_REPORT_ERROR聯(lián)合使用),?MYSQLI_REPORT_ERROR?(報(bào)告MYSQL錯(cuò)誤)和?MYSQLI_REPORT_INDEX?(報(bào)告索引相關(guān)的錯(cuò)誤)的任意組合。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類代表一個(gè)Mysql警告。
message消息字符串sqlstateSQL狀態(tài)errno錯(cuò)誤編號(hào)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 ;}別名和過(guò)時(shí)的Mysqli 函數(shù)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?— 開(kāi)啟從主機(jī)讀取mysqli_enable_rpl_parse?— 開(kāi)啟RPL解析mysqli_escape_string?— 別名 mysqli_real_escape_stringmysqli_execute?— mysqli_stmt_execute的別名mysqli_fetch?— mysqli_stmt_fetch的別名。mysqli_get_cache_stats?— 返回客戶端Zval緩存統(tǒng)計(jì)信息mysqli_get_metadata?— mysqli_stmt_result_metadata的別名mysqli_master_query?— 在主/從機(jī)制中強(qiáng)制在主機(jī)中執(zhí)行一個(gè)查詢mysqli_param_count?— mysqli_stmt_param_count的別名mysqli_report?— 開(kāi)啟或禁用(Mysql)內(nèi)部(錯(cuò)誤)報(bào)告函數(shù)mysqli_rpl_parse_enabled?— 檢查是否開(kāi)啟了RPL解析mysqli_rpl_probe?— RPL探測(cè)mysqli_send_long_data?— mysqli_stmt_send_long_data的別名mysqli_set_opt?— mysqli_options的別名mysqli_slave_query?— 在主/從機(jī)制中強(qiáng)制在從機(jī)上執(zhí)行一個(gè)查詢
相關(guān)文章:
1. IntelliJ IDEA設(shè)置背景圖片的方法步驟2. Java httpClient介紹以及使用示例3. python 日志模塊logging的使用場(chǎng)景及示例4. Android運(yùn)行時(shí)權(quán)限終極方案(PermissionX)5. Java 如何解析key為動(dòng)態(tài)的json操作6. 刪除docker里建立容器的操作方法7. Java反射技術(shù)原理與用法實(shí)例分析8. Android 使用 SharedPreferences 保存少量數(shù)據(jù)的實(shí)現(xiàn)代碼9. java實(shí)現(xiàn)基于TCP協(xié)議網(wǎng)絡(luò)socket編程(C/S通信)10. 淺析java并發(fā)中的Synchronized關(guān)鍵詞
