php 中 mysqli 是個類,這個類的函數(shù)(方法)有:
創(chuàng)新互聯(lián)2013年至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站制作、做網(wǎng)站網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元鼓樓做網(wǎng)站,已為上家服務(wù),為鼓樓各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
mysqli::$affected_rows — Gets the number of affected rows in a previous MySQL operation
mysqli::autocommit — 打開或關(guān)閉本次數(shù)據(jù)庫連接的自動命令提交事務(wù)模式
mysqli::begin_transaction — Starts a transaction
mysqli::change_user — Changes the user of the specified database connection
mysqli::character_set_name — 返回當(dāng)前數(shù)據(jù)庫連接的默認(rèn)字符編碼
mysqli::$client_info — Get MySQL client info
mysqli::$client_version — Returns the MySQL client version as a string
mysqli::close — 關(guān)閉先前打開的數(shù)據(jù)庫連接
mysqli::commit — 提交一個事務(wù)
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 — 將調(diào)試信息輸出到日志
mysqli::errno — 返回最近函數(shù)調(diào)用的錯誤代碼
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 — 作為一個整數(shù)返回MySQL客戶端的版本
mysqli::get_connection_stats — Returns statistics about the client connection
mysqli::$host_info — 返回一個表述使用的連接類型的字符串
mysqli::$protocol_version — 返回MySQL使用的協(xié)議版本號
mysqli::$server_info — 返回MySQL服務(wù)器的版本號
mysqli::$server_version — 作為一個整數(shù)返回MySQL服務(wù)器的版本
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 — 對數(shù)據(jù)庫執(zhí)行一次查詢
mysqli::real_connect — 建立一個 MySQL 服務(wù)器連接
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 — 執(zhí)行一個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 — 回退當(dāng)前事務(wù)
mysqli::rpl_query_type — Returns RPL query type
mysqli::savepoint — Set a named transaction savepoint
mysqli::select_db — 選擇用于數(shù)據(jù)庫查詢的默認(rèn)數(shù)據(jù)庫
mysqli::send_query — 發(fā)送請求并返回結(jié)果
mysqli::set_charset — 設(shè)置默認(rèn)字符編碼
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(調(diào)用)的對象
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
以上函數(shù)清單直接來自 網(wǎng)站。你可以進(jìn)入該網(wǎng)站參看。
1、用navicat新建一個數(shù)據(jù)庫database1。
2、在database1數(shù)據(jù)庫中新建一個表table2。
3、在table2中添加新的數(shù)據(jù),新建一個名稱為mysql_query的數(shù)據(jù)庫。
4、在頁面中用mysql_connect 函數(shù)與數(shù)據(jù)庫建立連接。
5、用mysql_select_db函數(shù)選擇要查詢的數(shù)據(jù)庫。
6、添加一個查詢 table2表的查詢語句“$sql=select * from table2“。
7、將查詢語句$sql添加到查詢數(shù)據(jù)庫函數(shù)mysql_query中,返回值賦值給變量query。
8、最后將mysql_query。php文件在瀏覽器中打開,查看查詢到數(shù)據(jù)庫中的內(nèi)容的結(jié)果。
在使用php session進(jìn)行數(shù)據(jù)查詢時主要有3中方法。第一種是使用函數(shù)【mysql_connect()】建立和MYSQL數(shù)據(jù)庫的連接。mysql_connect()是用來建立和MYSQL數(shù)據(jù)庫的連接,一共有5個參數(shù),一般情況下只使用前3個參數(shù),分別是MySQL服務(wù)器地址、用戶名以及密碼。第二種是使用函數(shù)【mysql_select_db()】指定要操作的數(shù)據(jù)庫。mysql_select_db()是用來指定要操作的數(shù)據(jù)庫。要是需要操作的數(shù)據(jù)庫還沒有創(chuàng)建,則需要創(chuàng)建數(shù)據(jù)庫,然后再創(chuàng)建數(shù)據(jù)庫中的表。第三種是使用函數(shù)【mysql_query()】查詢指令。mysql_query()是查詢指令的專用函數(shù),所有的SQL語句都通過它執(zhí)行,并返回結(jié)果集。一般情況下這三種方法是最適用的,希望可以解決你的問題。
1、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之 mysql_result()
mixed mysql_result(resource result_set, int row [,mixed field])
從result_set 的指定row 中獲取一個field 的數(shù)據(jù). 簡單但是效率低.
舉例:
$link1?=?@mysql_connect("server1",?
"webuser",?"password")?
or?die("Could?not?connect?
to?mysql?server!");
@mysql_select_db("company")?
or?die("Could?not?select?database!");
$query?=?"select?id,?name?
from?product?order?by?name";?
$result?=?mysql_query($query);
$id?=?mysql_result($result,?0,?"id");
$name?=?mysql_result($result,?0,?"name");
mysql_close();
注意,上述代碼只是輸出結(jié)果集中的第一條數(shù)據(jù)的字段值,如果要輸出所有記錄,需要循環(huán)處理.
for?($i?=?0;?$i?=?mysql_num_rows($result);?$i++)
{
$id?=?mysql_result($result,?0,?"id");
$name?=?mysql_result($result,?0,?"name");
echo?"Product:?$name?($id)";
}
注意,如果查詢字段名是別名,則mysql_result中就使用別名.
2、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_row()
array mysql_fetch_row(resource result_set)
從result_set中獲取整行,把數(shù)據(jù)放入數(shù)組中.
舉例(注意和list 的巧妙配合):
$query?=?"select?id,?
name?from?product?order?by?name";?
$result?=?mysql_query($query);
while(list($id,?$name)?
=?mysql_fetch_row($result))?{
echo?"Product:?$name?($id)";
}
3、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_array()
array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增強(qiáng)版.
將result_set的每一行獲取為一個關(guān)聯(lián)數(shù)組或/和數(shù)值索引數(shù)組.
默認(rèn)獲取兩種數(shù)組,result_type可以設(shè)置:
MYSQL_ASSOC:返回關(guān)聯(lián)數(shù)組,字段名=字段值?
MYSQL_NUM:返回數(shù)值索引數(shù)組.
MYSQL_BOTH:獲取兩種數(shù)組.因此每個字段可以按索引偏移引用,也可以按字段名引用.
舉例:
$query?=?"select?id,
name?from?product?order?by?name";
$result?=?mysql_query($query);
while($row?=?mysql_fetch_array
($result,?MYSQL_BOTH))?{?
$name?=?$row['name'];
//或者?$name?=?$row[1];
$name?=?$row['id'];
//或者?$name?=?$row[0];
echo?"Product:?$name?($id)";
}
4、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_assoc()
array mysql_fetch_assoc(resource result_set)
相當(dāng)于 mysql_fetch_array($result, MYSQL_ASSOC)
5、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_object()
object mysql_fetch_object(resource result_set)?
和mysql_fetch_array()功能一樣,不過返回的不是數(shù)組,而是一個對象.
舉例:
$query?=?"select?id,?name?
from?product?order?by?name";
$result?=?mysql_query($query);?
while($row?=?mysql_fetch_object
($result))?{
$name?=?$row-name;
$name?=?$row-id;
echo?"Product:?$name?($id)";
}
以上這些函數(shù)就是PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)的全部總結(jié)。