本文目錄一覽:
- 1、PHP中MySQLi和MySQL是一回事嗎?
- 2、PHP中的mysqli函數affected_rows()怎麼用?
- 3、php mysqli 常用函數有哪些
- 4、php怎麼用mysqli鏈接數據庫和輸出sql
PHP中MySQLi和MySQL是一回事嗎?
mysql與mysqli都是php方面的函數集,與mysql數據庫關聯不大。
在php5版本以後,增加了mysqli的函數功能,某種意義上講,它是mysql系統函數的增強版
PHP中的mysqli函數affected_rows()怎麼用?
看你是對象方式還是過程方式!
過程方式:
$Con = mysqli_connect(‘localhost’, ‘root’ , ”);//連接數據庫服務器
mysqli_select_db(‘data’);//選擇數據庫
mysqli_query( $Con, ‘Delete from 表名稱’);
mysqli_affected_rows( $Con );
對象方式:
$Con = new mysqli(‘localhost’, ‘root’, ”, ‘data’);
$Con – query(‘Delete from 表名稱’);
$Con – affected_rows;
php mysqli 常用函數有哪些
php 中 mysqli 是個類,這個類的函數(方法)有:
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 — 作為一個整數返回MySQL客戶端的版本
mysqli::get_connection_stats — Returns statistics about the client connection
mysqli::$host_info — 返回一個表述使用的連接類型的字符串
mysqli::$protocol_version — 返回MySQL使用的協議版本號
mysqli::$server_info — 返回MySQL服務器的版本號
mysqli::$server_version — 作為一個整數返回MySQL服務器的版本
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 — 建立一個 MySQL 服務器連接
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 — Removes the named savepoint from the set of savepoints of the current transaction
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
以上函數清單直接來自 網站。你可以進入該網站參看。
php怎麼用mysqli鏈接數據庫和輸出sql
一、mysql與mysqli的概念相關:
1、mysql與mysqli都是php方面的函數集,與mysql數據庫關聯不大。
2、在php5版本之前,一般是用php的mysql函數去驅動mysql數據庫的,比如mysql_query()的函數,屬於面向過程3、在php5版本以後,增加了mysqli的函數功能,某種意義上講,它是mysql系統函數的增強版,更穩定更高效更安全,與mysql_query()對應的有mysqli_query(),屬於面向對象,用對象的方式操作驅動mysql數據庫
二、mysql與mysqli的區別:
1、mysql是非持繼連接函數,mysql每次鏈接都會打開一個連接的進程。
2、mysqli是永遠連接函數,mysqli多次運行mysqli將使用同一連接進程,從而減少了服務器的開銷。mysqli封裝了諸如事務等一些高級操作,同時封裝了DB操作過程中的很多可用的方法。
三、mysql與mysqli的用法:
1:mysql(過程方式):
$conn =
mysql_connect(‘localhost’, ‘user’, ‘password’); //連接mysql數據庫mysql_select_db(‘data_base’);
//選擇數據庫$result =
mysql_query(‘select * from data_base’);//第二個可選參數,指定打開的連接$row =
mysql_fetch_row( $result ) ) //只取一行數據echo
$row[0]; //輸出第一個字段的值
PS:mysqli以過程式的方式操作,有些函數必須指定資源,比如mysqli_query(資源標識,SQL語句),並且資源標識的參數是放在前面的,而mysql_query(SQL語句,’資源標識’)的資源標識是可選的,默認值是上一個打開的連接或資源。
2、mysqli(對象方式):
$conn = new
mysqli(‘localhost’, ‘user’, ‘password’,’data_base’);//要使用new操作符,最後一個參數是直接指定數據庫//假如構造時候不指定,那下一句需要$conn – select_db(‘data_base’)實現$result =
$conn – query( ‘select * from data_base’ );$row =
$result – fetch_row(); //取一行數據echo
row[0]; //輸出第一個字段的值
使用new mysqli(‘localhost’, usenamer’, ‘password’, ‘databasename’);會報錯,提示如下:
Fatal error: Class ‘mysqli’ not found in …
一般是mysqli是沒有開啟的,因為mysqli類不是默認開啟的,win下要改php.ini,去掉php_mysqli.dll前的;,linux下要把mysqli編譯進去。
四、mysql_connect()與mysqli_connect()
1.使用mysqli,可以把數據庫名稱當作參數傳給mysqli_connect()函數,也可以傳遞給mysqli的構造函數;
2.如果調用mysqli_query()或mysqli的對象查詢query()方法,則連接標識是必需的。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/244555.html