通过PHP连接MYSQL的两种方法(
<br>mysql可通过两种方式通过PHP与web相连,一种通过php的mysql相关函数,另一种通过php的ODBC相关函数 <br>相关函数如下:
MYSQL函数
mysql_affected_rows: 得到 MySQL 最后操作影响的列数目。 <br>mysql_close: 关闭 MySQL 伺服器连线。 <br>mysql_connect: 开启 MySQL 伺服器连线。 <br>mysql_create_db: 建立一个 MySQL 新资料库。 <br>mysql_data_seek: 移动内部传回指标。 <br>mysql_db_query: 送查询字串 (query) 到 MySQL 资料库。 <br>mysql_drop_db: 移除资料库。 <br>mysql_errno: 传回错误讯息代码。 <br>mysql_error: 传回错误讯息。 <br>mysql_fetch_array: 传回阵列资料。 <br>mysql_fetch_field: 取得栏位资讯。 <br>mysql_fetch_lengths: 传回单列各栏资料最大长度。 <br>mysql_fetch_object: 传回物件资料。 <br>mysql_fetch_row: 传回单列的各栏位。 <br>mysql_field_name: 传回指定栏位的名称。 <br>mysql_field_seek: 设定指标到传回值的某栏位。 <br>mysql_field_table: 获得目前栏位的资料表 (table) 名称。 <br>mysql_field_type: 获得目前栏位的型态。 <br>mysql_field_flags: 获得目前栏位的旗标。 <br>mysql_field_len: 获得目前栏位的长度。 <br>mysql_free_result: 释放传回占用记忆体。 <br>mysql_insert_id: 传回最后一次使用 INSERT 指令的 ID。 <br>mysql_list_fields: 列出指定资料表的栏位 (field)。 <br>mysql_list_dbs: 列出 MySQL 伺服器可用的资料库 (database)。 <br>mysql_list_tables: 列出指定资料库的资料表 (table)。 <br>mysql_num_fields: 取得传回栏位的数目。 <br>mysql_num_rows: 取得传回列的数目。 <br>mysql_pconnect: 开启 MySQL 伺服器长期连线。 <br>mysql_query: 送出一个 query 字串。 <br>mysql_result: 取得查询 (query) 的结果。 <br>mysql_select_db: 选择一个资料库。 <br>mysql_tablename: 取得资料表名称。
ODBC函数 <br>使用ODBC函数需安装MYSQL ODBC
odbc_autocommit: 开关自动更动功能。 <br>odbc_binmode: 设定二进位资料处理方式。 <br>odbc_close: 关闭 ODBC 连结。 <br>odbc_close_all: 关闭所有 ODBC 连结。 <br>odbc_commit: 更动 ODBC 资料库。 <br>odbc_connect: 连结至 ODBC 资料库。 <br>odbc_cursor: 取得游标名。 <br>odbc_do: 执行 SQL 指令。 <br>odbc_exec: 执行 SQL 指令。 <br>odbc_execute: 执行预置 SQL 指令。 <br>odbc_fetch_into: 取得传回的指定列。 <br>odbc_fetch_row: 取得传回一列。 <br>odbc_field_name: 取得栏位名称。 <br>odbc_field_type: 取得栏位资料形态。 <br>odbc_field_len: 取得栏位资料长度。 <br>odbc_free_result: 释出传回资料的记忆体。 <br>odbc_longreadlen: 设定传回栏的最大值。 <br>odbc_num_fields: 取得栏位数目。 <br>odbc_pconnect: 长期连结至 ODBC 资料库。 <br>odbc_prepare: 预置 SQL 指令。 <br>odbc_num_rows: 取得传回列数目。 <br>odbc_result: 取得传回资料。 <br>odbc_result_all: 传回 HTML 表格资料。 <br>odbc_rollback: 撤消当前交易。 <br>odbc_setoption: 调整 ODBC 设定。
例子可见我在本网站的"程序与代码"里的文章和下面的例程: <br>前台HTML <br><form enctype="multipart/form-data" action="hb_ggzd.php" method="post" > <br><tr> <br><td width="251"><small>您 可 以 花 些 时 间 填 写 下 表 , 也 可 以 用 电 <br>子 邮 件 联 系 ,<a href="mailto:likai333@21cn.com">likai333@21cn.com</a>。</small></td> <br></tr> <br><tr> <br><td vAlign="top" width="251" height="31"><small>您的姓名:</small></td> <br><td width="462" height="31"><small><input name="name" size="20"> </small></td> <br></tr> <br><tr> <br><td vAlign="top" width="251" height="30"><small>您的电子邮件:</small></td> <br><td width="462" height="30"><small><input name="usermail" size="37"></small></td> <br></tr> <br><tr> <br><td vAlign="top" width="251" height="25"><small>您欲做广告的网站地址:</small></td> <br><td width="462" height="25"><small><small><input name="userurl" size="37" value="http://"></small></small></td> <br></tr> <br><tr> <br><td vAlign="top" width="251" height="25"><small>您欲做广告的网站站名:</small></td> <br><td width="462" height="25"><small><input name="sitename" size="20"></small></td> <br></tr> <br><tr> <br><td vAlign="top" width="251" height="30"><small>您的公司名称:</small></td> <br><td width="462" height="30"><small><input name="company" size="37"></small></td> <br></tr> <br><tr> <br><td vAlign="top" width="251" height="25"><small>您的联系电话:</small></td> <br><td width="462" height="25"><small><input name="phone" size="20"></small></td> <br></tr> <br><tr> <br>后台PHP
<?php <br>$dbh = mysql_connect(’localhost:3306’,’root’,’’); <br>mysql_select_db(’HBWEB’); <br>$query ="insert into usemsg ( name,usermail,userurl,sitename, company,phone) values (’$name’,’$usermail’,’$userurl’, ’$sitename’, ’$company’,’$phone’,’$C1’,’$C2’,’$C3’,’$C4’,’$C5’)"; <br>$res = mysql_query($query, $dbh); <br>$err = mysql_error(); <br>if($err){ <br>echo "发生错误,请通知<a href=mailto:likai333@21cn.com>我</a>"; <br>echo "$err"; <br>} <br>else <br>{ echo "成功入库"; }
?>
表结构: <br>CREATE TABLE usemsg ( <br>name varchar(255) not null default "notname", <br>usermail varchar(255) not null default "notusermail", <br>userurl varchar(255) not null default "notuserurl", <br>sitename varchar(255) not null default "notsitename", <br>company varchar(255) not null default "notcompany", <br>phone varchar(255) not null default "notphone", <br>);
|
kehui
|
|
智慧家居
智慧家居颠覆传统智能家居
智慧云谷让智能家居变成有智慧的
智慧云谷引领智慧家居新生活
科技改变生活 智慧云谷智慧家居系
智慧家居领航者,智慧云谷助你玩
智能家居如何赢得市场美誉度?
智慧云谷智慧家居:创业者有无限
WiFi智能家居你还在用?这样的智
互联网+助推智能家居产业
智慧云谷为您打造真正的智能家居
智能家居产业需要的不是单品,而
新家如何选择开关?智慧云谷iWis
智能传感器-世界首款“智”为你的
智慧云谷开关智能安防智能空气质
智能开关品牌,如何选择智能开关
秋季干燥,智慧家居温湿度传感器
传感器助力智慧家居 感知爱家
iWiscloud智能触摸开关缔造家居装
※室内空气污染的危害及 [sensor]
※超声波风速传感器在生 [sensor]
※这么冷清 [gabc111]
※手机APP操作有问题 [ssy11407]
※智慧云谷智慧家居将在 [cici]
※上传下载 [cici]
※下载智慧家居 [apple2008]
※秋季干燥,智慧家居温 [apple2008]
※智慧家居紧扣热点 安全 [apple2008]
※办公大楼如何智慧化管 [apple2008]
※智慧云谷工业自控的优 [apple2008]
※传感器助力智慧家居 感 [apple2008]
※智能开关品牌,如何选 [apple2008]
※智慧云谷开关智能安防 [apple2008]
※没有专业人员,如何安 [apple2008]
※烟台智慧云谷董事长任 [apple2008]
※互联网+助推智能家居产 [apple2008]
※WiFi智能家居你还在用 [apple2008]
※智慧云谷智慧家居:创 [apple2008]
※智能家居如何赢得市场 [apple2008]
|