程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 解析PHP連接MYSQL的兩種方法

解析PHP連接MYSQL的兩種方法

編輯:關於PHP編程

Mysql可通過兩種方式通過PHP與web相連,一種通過php的Mysql相關函數,另一種通過php的ODBC相關函數。

  相關函數如下:

  MYSQL函數

  mysql_affected_rows: 得到 MySQL 最後操作影響的列數目。

  mysql_close: 關閉 MySQL 伺服器連線。

  mysql_connect: 開啟 MySQL 伺服器連線。

  mysql_create_db: 建立一個 MySQL 新資料庫。

  mysql_data_seek: 移動內部傳回指標。

  mysql_db_query: 送查詢字串 (query) 到 MySQL 資料庫。

  mysql_drop_db: 移除資料庫。

  mysql_errno: 傳回錯誤訊息代碼。

  mysql_error: 傳回錯誤訊息。

  mysql_fetch_array: 傳回陣列資料。

  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: 釋放傳回占用記憶體。

  mysql_insert_id: 傳回最後一次使用 INSERT 指令的 ID。

  mysql_list_fields: 列出指定資料表的欄位 (field)。

  mysql_list_dbs: 列出 MySQL 伺服器可用的資料庫 (database)。

  mysql_list_tables: 列出指定資料庫的資料表 (table)。

  mysql_num_fields: 取得傳回欄位的數目。

  mysql_num_rows: 取得傳回列的數目。

  mysql_pconnect: 開啟 MySQL 伺服器長期連線。

  mysql_query: 送出一個 query 字串。

  mysql_result: 取得查詢 (query) 的結果。

  mysql_select_db: 選擇一個資料庫。

  mysql_tablename: 取得資料表名稱。

  ODBC函數

  使用ODBC函數需安裝MYSQL ODBC

  odbc_autocommit: 開關自動更動功能。

  odbc_binmode: 設定二進位資料處理方式。

  odbc_close: 關閉 ODBC 連結。

  odbc_close_all: 關閉所有 ODBC 連結。

  odbc_commit: 更動 ODBC 資料庫。

  odbc_connect: 連結至 ODBC 資料庫。

  odbc_cursor: 取得游標名。

  odbc_do: 執行 SQL 指令。

  odbc_exec: 執行 SQL 指令。

  odbc_execute: 執行預置 SQL 指令。

  odbc_fetch_into: 取得傳回的指定列。

  odbc_fetch_row: 取得傳回一列。

  odbc_field_name: 取得欄位名稱。

  odbc_field_type: 取得欄位資料形態。

  odbc_field_len: 取得欄位資料長度。

  odbc_free_result: 釋出傳回資料的記憶體。

  odbc_longreadlen: 設定傳回欄的最大值。

  odbc_num_fields: 取得欄位數目。

  odbc_pconnect: 長期連結至 ODBC 資料庫。

  odbc_prepare: 預置 SQL 指令。

  odbc_num_rows: 取得傳回列數目。

  odbc_result: 取得傳回資料。

  odbc_result_all: 傳回 HTML 表格資料。

  odbc_rollback: 撤消當前交易。

  odbc_setoption: 調整 ODBC 設定。

  例子:前台HTML
< form enctype="multipart/form-data" action="hb_ggzd.php" method="post" >
< tr >
< td width="251" >< small >您 可 以 花 些 時 間 填 寫 下 表 , 也 可 以 用 電
子 郵 件 聯 系 ,< a href="mailto:[email protected]" >[email protected]< /a >。< /small >< /td >
< /tr >
< tr >
< td vAlign="top" width="251" height="31" >< small >您的姓名:< /small >< /td >
< td width="462" height="31" >< small >< input name="name" size="20" > < /small >< /td >
< /tr >
< tr >
< td vAlign="top" width="251" height="30" >< small >您的電子郵件:< /small >< /td >
< td width="462" height="30" >< small >< input name="usermail" size="37" >< /small >< /td >
< /tr >
< tr >
< td vAlign="top" width="251" height="25" >< small >您欲做廣告的網站地址:< /small >< /td >
< td width="462" height="25" >< small >< small >< input name="userurl" size="37" value="http://" >< /small >< /small >< /td >
< /tr >
< tr >
< td vAlign="top" width="251" height="25" >< small >您欲做廣告的網站站名:< /small >< /td >
< td width="462" height="25" >< small >< input name="sitename" size="20" >< /small >< /td >
< /tr >
< tr >
< td vAlign="top" width="251" height="30" >< small >您的公司名稱:< /small >< /td >
< td width="462" height="30" >< small >< input name="company" size="37" >< /small >< /td >
< /tr >
< tr >
< td vAlign="top" width="251" height="25" >< small >您的聯系電話:< /small >< /td >
< td width="462" height="25" >< small >< input name="phone" size="20" >< /small >< /td >
< /tr >
< tr >


  後台PHP :
< ?php
= mysql_connect(localhost:3306,root,);
mysql_select_db(HBWEB);
="insert into usemsg ( name,usermail,userurl,sitename, company,phone) values (,,, , ,,,,,,)";
= mysql_query(, );
= mysql_error();
if(){
echo "發生錯誤,請通知< a href=mailto:[email protected] >我< /a >";
echo "";
}
else
{ echo "成功入庫"; }
? >

  表結構:
CREATE TABLE usemsg (
name varchar(255) not null default "notname",
usermail varchar(255) not null default "notusermail",
userurl varchar(255) not null default "notuserurl",
sitename varchar(255) not null default "notsitename",
company varchar(255) not null default "notcompany",
phone varchar(255) not null default "notphone",
);

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved