WEB中运用PHP连接MySQL的办法?
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP和MYSQL组合编程<span style="color: black;">已然</span><span style="color: black;">作为</span>WEB<span style="color: black;">研发</span>中比较流行的一种方式,<span style="color: black;">针对</span>新手来讲,<span style="color: black;">她们</span>可能会问:PHP<span style="color: black;">为何</span>能够操作MySQL数据库,PHP是<span style="color: black;">怎样</span>和MySQL组合编程的呢,有<span style="color: black;">那些</span>方式<span style="color: black;">能够</span>实现PHP连接MySQL数据库呢?接下来,本文将一一来为你解答这些问题。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Q、PHP<span style="color: black;">为何</span>能操作MySQL?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">A、PHP安装目录中有一个名为ext的专门存放PHP扩展文件的目录,其中有一个叫php_mysql.dll的扩展,该扩展<span style="color: black;">能够</span><span style="color: black;">运用</span>PHP能够操作MYSQL,当然使该扩展起<span style="color: black;">功效</span>,还得做<span style="color: black;">关联</span>的设置才<span style="color: black;">能够</span>用,那<span style="color: black;">便是</span>要在PHP配置文件php.ini中找到如下一行:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;extension=php_mysql.dll</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">去掉该行全面的分号,<span style="color: black;">而后</span><span style="color: black;">保留</span>该文件,重启Apache服务器,该扩展就<span style="color: black;">能够</span>生效<span style="color: black;">运用</span>了。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Q、PHP连接MYSQL的<span style="color: black;">办法</span>有<span style="color: black;">那些</span>呢?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">A、有两种方式:<span style="color: black;">第1</span>种<span style="color: black;">便是</span><span style="color: black;">经过</span>php的mysql<span style="color: black;">关联</span>函数来连接,另一种<span style="color: black;">经过</span>php的ODBC<span style="color: black;">关联</span>函数。这两种<span style="color: black;">办法</span>的连接过程都差不多,都是先<span style="color: black;">创立</span>连接,<span style="color: black;">而后</span>再<span style="color: black;">经过</span>PHP页面提交数据至MySQL,存储成功给出成功提示,不成功则提示失败。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Q、<span style="color: black;">怎样</span>实现PHP和MySQL组合编程?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">A、<span style="color: black;">经过</span>开启PHP扩展库(php_mysql.dll、php_mysqli.dll、php_pdo_mysql.dll、php_pdo_odbc.dll),再<span style="color: black;">经过</span>这些扩展的函数,<span style="color: black;">咱们</span>就<span style="color: black;">能够</span>实现PHP+MySQL组合编程了。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">附:PHP操作MySQL的<span style="color: black;">关联</span>函数</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、MYSQL函数</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_affected_rows: 得到 MySQL 最后操作影响的列数目。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_close: 关闭 MySQL 伺服器连线。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_connect: 开启 MySQL 伺服器连线。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_create_db: <span style="color: black;">创立</span>一个 MySQL 新资料库。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_data_seek: 移动内部传回指标。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_db_query: 送<span style="color: black;">查找</span>字串 (query) 到 MySQL 资料库。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_drop_db: 移除资料库。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_errno: 传回错误讯息代码。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_error: 传回错误讯息。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_fetch_array: 传回阵列资料。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_fetch_field: 取得栏位<span style="color: black;">新闻</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_fetch_lengths: 传回单列各栏资料最大长度。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_fetch_object: 传回物件资料。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_fetch_row: 传回单列的各栏位。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_field_name: 传回指定栏位的名<span style="color: black;">叫作</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_field_seek: 设定指标到传回值的某栏位。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_field_table: <span style="color: black;">得到</span><span style="color: black;">日前</span>栏位的资料表 (table) 名<span style="color: black;">叫作</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_field_type: <span style="color: black;">得到</span><span style="color: black;">日前</span>栏位的型态。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_field_flags: <span style="color: black;">得到</span><span style="color: black;">日前</span>栏位的旗标。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_field_len: <span style="color: black;">得到</span><span style="color: black;">日前</span>栏位的长度。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_free_result: 释放传回占用记忆体。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_insert_id: 传回最后一次<span style="color: black;">运用</span> INSERT 指令的 ID。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_list_fields: 列出指定资料表的栏位 (field)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_list_dbs: 列出 MySQL 伺服器可用的资料库 (database)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_list_tables: 列出指定资料库的资料表 (table)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_num_fields: 取得传回栏位的数目。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_num_rows: 取得传回列的数目。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_pconnect: 开启 MySQL 伺服器<span style="color: black;">长时间</span>连线。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_query: 送出一个 query 字串。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_result: 取得<span style="color: black;">查找</span> (query) 的结果。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_select_db: <span style="color: black;">选取</span>一个资料库。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_tablename: 取得资料表名<span style="color: black;">叫作</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、ODBC函数(<span style="color: black;">运用</span>ODBC函数需安装MYSQL ODBC)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">odbc_autocomm</p>
“板凳”(第三个回帖的人) 感谢你的精彩评论,带给我新的思考角度。 楼主的文章深得我心,表示由衷的感谢!
页:
[1]