mysql_affected_rows: 得到 MySQL 最后操作影響的列數(shù)目。 mysql_close: 關閉 MySQL 服務器連接。 mysql_connect: 打開 MySQL 服務器連接。 mysql_create_db: 建立一個 MySQL 新數(shù)據(jù)庫。 mysql_data_seek: 移動內(nèi)部返回指針。 mysql_db_query: 送查詢字符串 (query) 到 MySQL 數(shù)據(jù)庫。 mysql_drop_db: 移除數(shù)據(jù)庫。 mysql_errno: 返回錯誤信息代碼。 mysql_error: 返回錯誤信息。 mysql_fetch_array: 返回數(shù)組資料。 mysql_fetch_field: 取得字段信息。 mysql_fetch_lengths: 返回單列各欄資料最大長度。 mysql_fetch_object: 返回類資料。 mysql_fetch_row: 返回單列的各字段。 mysql_field_name: 返回指定字段的名稱。 mysql_field_seek: 配置指針到返回值的某字段。 mysql_field_table: 獲得目前字段的資料表 (table) 名稱。 mysql_field_type: 獲得目前字段的類型。 mysql_field_flags: 獲得目前字段的標志。 mysql_field_len: 獲得目前字段的長度。 mysql_free_result: 釋放返回占用內(nèi)存。 mysql_insert_id: 返回最后一次使用 INSERT 指令的 ID。 mysql_list_fields: 列出指定資料表的字段 (field)。 mysql_list_dbs: 列出 MySQL 服務器可用的數(shù)據(jù)庫 (database)。 mysql_list_tables: 列出指定數(shù)據(jù)庫的資料表 (table)。 mysql_num_fields: 取得返回字段的數(shù)目。 mysql_num_rows: 取得返回列的數(shù)目。 mysql_pconnect: 打開 MySQL 服務器持續(xù)連接。 mysql_query: 送出一個 query 字符串。 mysql_result: 取得查詢 (query) 的結果。 mysql_select_db: 選擇一個數(shù)據(jù)庫。 mysql_tablename: 取得資料表名稱。
mysql_affected_rows 得到 MySQL 最后操作影響的列數(shù)目。 語法: int mysql_affected_rows(int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可得到 MySQL 最后查詢操作 INSERT、UPDATE 或 DELETE 所影響的列 (row) 數(shù)目。若最后的查詢 (query) 是使用 DELETE 而且沒有使用 WHERE 命令,則會刪除全部資料,本函數(shù)將返回 0。若最后使用的是 SELECT,則用本函數(shù)不會得到預期的數(shù)目,因為要改變 MySQL 數(shù)據(jù)庫本函數(shù)才有效,欲得到 SELECT 返回的數(shù)目需使用 mysql_num_rows() 函數(shù)。
mysql_close 關閉 MySQL 服務器連接。 語法: int mysql_close(int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)關閉與 MySQL 數(shù)據(jù)庫服務器的連接。若無指定參數(shù) link_identifier 則會關閉最后的一筆連接。用 mysql_pconnect() 連接則無法使用本函數(shù)關閉。實際上本函數(shù)不是一定需要的,當 PHP 整頁程序結束后,將會自動關閉與數(shù)據(jù)庫的非永久性 (non-persistent) 連接。成功返回 true、失敗返回 false 值。 參考: mysql_connect() mysql_pconnect()
mysql_connect 打開 MySQL 服務器連接。 語法: int mysql_connect(string [hostname] [:port], string [username], string [password]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)建立與 MySQL 服務器的連接。其中所有的參數(shù)都可省略。當使用本函數(shù)卻不加任何參數(shù)時,參數(shù) hostname 的默認值為 localhost、參數(shù) username 的默認值為 PHP 執(zhí)行行程的擁有者、參數(shù) password 則為空字符串 (即沒有密碼)。而參數(shù) hostname 后面可以加冒號與埠號,代表使用那個埠與 MySQL 連接。當然在使用數(shù)據(jù)庫時,早點使用 mysql_close() 將連接關掉可以節(jié)省資源。 使用范例 這是一位未具名網(wǎng)友提供的范例 (18-Feb-1999) <?php $dbh = mysql_connect(‘localhost:3306‘,‘mcclain‘,‘standard‘); mysql_select_db(‘a(chǎn)dmreqs‘); $query = "insert into requests(date, request, email, priority,status) s (NOW(),‘$deion‘, ‘$email‘, ‘$priority‘, ‘NEW‘)"; $res = mysql_query($query, $dbh); $query = "select max(id) from requests"; $res = mysql_query($query, $dbh); $err = mysql_error(); if($err){ echo "發(fā)生錯誤,請通知<a href=mailto:webmaster@my.site>站長</a>"; } $row = mysql_fetch_row($res); echo "未來您使用的號碼為: ".$row[0]; ?> 參考: mysql_close() mysql_pconnect()
mysql_create_db 建立一個 MySQL 新數(shù)據(jù)庫。 語法: int mysql_create_db(string database name, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)用來建立新的數(shù)據(jù)庫 (database)。在建立前,必須先與服務器連接。 參考: mysql_drop_db()
mysql_data_seek 移動內(nèi)部返回指針。 語法: int mysql_data_seek(int result_identifier, int row_number); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可移動內(nèi)部返回的列指針到指定的 row_number 去。之后若使用 mysql_fetch_row() 可以返回新列的值。成功返回 true、失敗則返回 false。
mysql_db_query 送查詢字符串 (query) 到 MySQL 數(shù)據(jù)庫。 語法: int mysql_db_query(string database, string query, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)用來送出查詢字符串 (query) 到后端的 MySQL 數(shù)據(jù)庫中。而可省略的參數(shù) link_identifier 若不存在,程序會自動尋找其它 mysql_connect() 連接后的連接代碼。發(fā)生錯誤時會返回 false,其它沒錯誤時則返回它的返回代碼。 參考: mysql_connect()
mysql_drop_db 移除數(shù)據(jù)庫。 語法: int mysql_drop_db(string database_name, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)移除已存在的數(shù)據(jù)庫。成功返回 true、失敗則返回 false。 參考: mysql_create_db()
mysql_errno 返回錯誤信息代碼。 語法: int mysql_errno(int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到 MySQL 數(shù)據(jù)庫服務器的錯誤代碼。通常用在 PHP 網(wǎng)頁程序開發(fā)階段,作為 PHP 與 MySQL 的除錯用。 使用范例 <?php mysql_connect("marliesle"); echo mysql_errno().": ".mysql_error()."<BR>"; mysql_select_db("nonexistentdb"); echo mysql_errno().": ".mysql_error()."<BR>"; $conn = mysql_query("SELECT * FROM nonexistenttable"); echo mysql_errno().": ".mysql_error()."<BR>"; ?> 參考: mysql_error()
mysql_error 返回錯誤信息。 語法: string mysql_error(int [link_identifier]); 返回值: 字符串 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到 MySQL 數(shù)據(jù)庫服務器的錯誤信息。通常用在 PHP 網(wǎng)頁程序開發(fā)階段,與 mysql_errno() 一起作為PHP 與 MySQL 的除錯用。 參考: mysql_errno()
mysql_fetch_array 返回數(shù)組資料。 語法: array mysql_fetch_array(int result, int [result_typ]); 返回值: 數(shù)組 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)用來將查詢結果 result 拆到數(shù)組變量中。若 result 沒有資料,則返回 false 值。而本函數(shù)可以說是 mysql_fetch_row() 的加強函數(shù),除可以將返回列及數(shù)字索引放入數(shù)組之外,還可以將文字索引放入數(shù)組中。若是好幾個返回字段都是相同的文字名稱,則最后一個置入的字段有效,解決方法是使用數(shù)字索引或者為這些同名的字段 (column) 取別名 (alias)。治募?注意的是使用本函數(shù)的處理速度其實不會比 mysql_fetch_row() 函數(shù)慢,要用哪個函數(shù)還是看使用的需求決定。參數(shù) result_typ 是一個常量值,有以下幾種常量 MYSQL_ASSOC、MYSQL_NUM 與 MYSQL_BOTH。 使用范例 <?php mysql_connect($host,$user,$password); $result = mysql_db_query("database","select * from table"); while($row = mysql_fetch_array($result)) { echo $row["user_id"]; echo $row["fullname"]; } mysql_free_result($result); ?>
mysql_fetch_field 取得字段信息。 語法: object mysql_fetch_field(int result, int [field_offset]); 返回值: 類 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)返回的類資料為 result 的字段 (Column) 信息。返回類的屬性如下: name - 字段名稱 table - 字段所在表格的資料表名稱 max_length - 字段的最大長度 not_null - 若為 1 表示本字段不能是空的 (null) primary_key - 若為 1 表示本字段是主要鍵 (primary key) unique_key - 若為 1 表示本字段為不可重覆鍵 (unique key) multiple_key - 若為 1 表示本字段為可重覆鍵 (non-unique key) numeric - 若為 1 表示本字段為數(shù)字類型 (numeric) blob - 若為 1 表示本字段為位類型 (BLOB) type - 字段類型 unsigned - 若為 1 表示本字段為無記號 (unsigned) zerofill - 若為 1 表示本字段為被零填滿 (zero-filled) 參考: mysql_field_seek()
mysql_fetch_lengths 返回單列各欄資料最大長度。 語法: array mysql_fetch_lengths(int result); 返回值: 數(shù)組 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)將 mysql_fetch_row() 處理過的最后一列資料的各字段資料最大長度放在數(shù)組變量之中。若執(zhí)行失敗則返回 false 值。返回數(shù)組的第一筆資料索引值是 0。 參考: mysql_fetch_row()
mysql_fetch_object 返回類資料。 語法: object mysql_fetch_object(int result, int [result_typ]); 返回值: 類 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)用來將查詢結果 result 拆到類變量中。使用方法和 mysql_fetch_array() 幾乎相同,不同的地方在于本函數(shù)返回資料是類而不是數(shù)組。若 result 沒有資料,則返回 false 值。另外治募?注意的地方是,取回的類資料的索引只能是文字而不能用數(shù)字,這是因為類的特性。類資料的特性中所有的屬性 (property) 名稱都不能是數(shù)字,因此只好乖乖使用文字字符串當索引了。參數(shù) result_typ是一個常量值,有以下幾種常量 MYSQL_ASSOC、MYSQL_NUM 與 MYSQL_BOTH。關于速度方面,本函數(shù)的處理速度幾乎和 mysql_fetch_row() 及 mysql_fetch_array() 二函數(shù)差不多,要用哪個函數(shù)還是看使用的需求決定。 使用范例 下面的例子示范如使用返回的類。 <?php mysql_connect($host,$user,$password); $result = mysql_db_query("MyDatabase","select * from test"); while($row = mysql_fetch_object($result)) { echo $row->user_id; echo $row->fullname; } mysql_free_result($result); ?> 參考: mysql_fetch_array() mysql_fetch_row()
mysql_fetch_row 返回單列的各字段。 語法: array mysql_fetch_row(int result); 返回值: 數(shù)組 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)用來將查詢結果 result 之單列拆到數(shù)組變量中。數(shù)組的索引是數(shù)字索引,第一個的索引值是 0。若 result 沒有資料,則返回 false 值。 參考: mysql_fetch_array() mysql_fetch_object() mysql_data_seek() mysql_fetch_lengths() mysql_result()
mysql_field_name 返回指定字段的名稱。 語法: string mysql_field_name(int result, int field_index); 返回值: 字符串 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)用來取得指定字段的名稱。 使用范例 mysql_field_name($result,2);
mysql_field_seek 配置指針到返回治募?某字段。 語法: int mysql_field_seek(int result, int field_offset); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)配置目前的指針到返回治募?特定字段中。 參考: mysql_fetch_field()
mysql_field_table 獲得目前字段的資料表 (table) 名稱。 語法: string mysql_field_table(int result, int field_offset); 返回值: 字符串 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到目前所在字段的資料表名。
mysql_field_type 獲得目前字段的類型。 語法: string mysql_field_type(int result, int field_offset); 返回值: 字符串 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到目前所在字段的類型格式。返回的字符串為字段的類型,包括了 int、real、string、blob....等等,詳見 MySQL 的相關文件中有關于類型的部份。 使用范例 <?php mysql_connect("localhost:3306"); mysql_select_db("wisconsin"); $result = mysql_query("SELECT * FROM onek"); $fields = mysql_num_fields($result); $rows = mysql_num_rows($result); $i = 0; $table = mysql_field_table($result, $i); echo "資料表 ‘".$table."‘ 有 ".$fields." 欄及 ".$rows." 列。<br>"; echo "本資料表的字段如下<br>"; while ($i < $fields) { $type = mysql_field_type ($result, $i); $name = mysql_field_name ($result, $i); $len = mysql_field_len ($result, $i); $flags = mysql_field_flags ($result, $i); echo $type." ".$name." ".$len." ".$flags."<br>"; $i++; } mysql_close(); ?>
mysql_field_flags 獲得目前字段的標志。 語法: string mysql_field_flags(int result, int field_offset); 返回值: 字符串 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到目前所在字段的標志。若一個字段有數(shù)種屬性標志,則返回的標志為這些屬性連起來的字符串,每個屬性都用空格隔開,可以使用 explode() 切開這些字符串。返回的標志可能是:not_null、primary_key、unique_key、multiple_key、blob、unsigned、zerofill、binary、enum、auto_increment、timestamp。
mysql_field_len 獲得目前字段的長度。 語法: int mysql_field_len(int result, int field_offset); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到目前所在字段的長度。
mysql_free_result 釋放返回占用內(nèi)存。 語法: boolean mysql_free_result(int result); 返回值: 布爾值 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以釋放目前 MySQL 數(shù)據(jù)庫 query 返回所占用的內(nèi)存。一般只有在非常擔心在內(nèi)存的使用上可能會不足的情形下才會用本函數(shù)。PHP 程序會在結束時自動釋放。
mysql_insert_id 返回最后一次使用 INSERT 指令的 ID。 語法: int mysql_insert_id(int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到最后一次使用 INSERT 到 MySQL 數(shù)據(jù)庫的執(zhí)行 ID。sleibowitz@btcwcu.org (13-May-1999) 指出在 PHP 3.0.7 版用 REPLACE 也和使用 INSERT 一樣,可以使用本函數(shù)獲得 ID。
mysql_list_fields 列出指定資料表的字段 (field)。 語法: int mysql_list_fields(string database_name, string table_name, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到指定的資料表的所有字段。返回的字段信息可以供 mysql_field_flags()、mysql_field_len()、mysql_field_name() 及 mysql_field_type() 等函數(shù)使用。若有錯誤則返回 -1。
mysql_list_dbs 列出 MySQL 服務器可用的數(shù)據(jù)庫 (database)。 語法: int mysql_list_dbs(int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到 MySQL 服務器的可用數(shù)據(jù)庫。
mysql_list_tables 列出指定數(shù)據(jù)庫的資料表 (table)。 語法: int mysql_list_tables(string database, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到指定數(shù)據(jù)庫中的所有資料表名稱。
mysql_num_fields 取得返回字段的數(shù)目。 語法: int mysql_num_fields(int result); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到返回字段的數(shù)目。 參考: mysql_db_query() mysql_query() mysql_fetch_field() mysql_num_rows()
mysql_num_rows 取得返回列的數(shù)目。 語法: int mysql_num_rows(int result); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可以得到返回列的數(shù)目。 參考: mysql_db_query() mysql_query() mysql_fetch_row()
mysql_pconnect 打開 MySQL 服務器持續(xù)連接。 語法: int mysql_pconnect(string [hostname] [:port], string [username], string [password]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)和 mysql_connect() 雷同。不同的地方在于使用本函數(shù)打開數(shù)據(jù)庫時,程序會先尋找是否曾經(jīng)執(zhí)行過本函數(shù),若執(zhí)行過則返回先前執(zhí)行的 ID。另一個不同的地方是本函數(shù)無法使用 mysql_close() 關閉數(shù)據(jù)庫。
mysql_query 送出一個 query 字符串。 語法: int mysql_query(string query, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)送出 query 字符串供 MySQL 做相關的處理或者執(zhí)行。若沒有指定 link_identifier 參數(shù),則程序會自動尋找最近打開的 ID。當 query 查詢字符串是 UPDATE、INSERT 及 DELETE 時,返回的可能是 true 或者 false;查詢的字符串是 SELECT 則返回新的 ID 值。joey@samaritan.com (09-Feb-1999) 指出,當返回 false 時,并不是執(zhí)行成功但無返回值,而是查詢的字符串有錯誤。 參考: mysql_db_query() mysql_select_db() mysql_connect()
mysql_result 取得查詢 (query) 的結果。 語法: int mysql_result(int result, int row, mixed field); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)取得一格 query 的結果。參數(shù) field 可以是字段名稱、順序或者是 FieldName.TableName 的格式。在返回資料量少時,可以使用本函數(shù)來處理。當數(shù)據(jù)庫大時,本函數(shù)的效率就有待考量了,這時可以使用較有效率的 mysql_fetch_row()、mysql_fetch_array() 及 mysql_fetch_object() 等函數(shù)。
mysql_select_db 選擇一個數(shù)據(jù)庫。 語法: int mysql_select_db(string database_name, int [link_identifier]); 返回值: 整數(shù) 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)選擇 MySQL 服務器中的數(shù)據(jù)庫以供之后的資料查詢作業(yè) (query) 處理。成功返回 true,失敗則返回 false。 參考: mysql_connect() mysql_pconnect() mysql_query()
mysql_tablename 取得資料表名稱。 語法: string mysql_tablename(int result, int i); 返回值: 字符串 函數(shù)種類: 數(shù)據(jù)庫功能 內(nèi)容說明: 本函數(shù)可取得資料表名稱字符串,一般配合 mysql_list_tables() 函數(shù)使用,取得該函返回的數(shù)字的名稱字符串。 使用范例 <?php mysql_connect ("localhost:3306"); $result = mysql_list_tables ("wisconsin"); $i = 0; while ($i < mysql_num_rows ($result)) { $tb_names[$i] = mysql_tablename ($result, $i); echo $tb_names[$i] . "<BR>"; $i++; } ?>
|