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>的编译选项:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">--with-mysql</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">--with-mysqli</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">--with-pdo-mysql</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">--enable-mysqlnd</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">那这几个选项到底有什么<span style="color: black;">区别</span>呢?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php官方文档上有这么一段话:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MySQL:This extension is deprecated as of PHP 5.5.0, and has been removed as of php 7.0.0.</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MYSQLI: mysql Improved Extension </p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MySQLND: MySQL Native Drive </p>PDO:The PHP Data Objects。extension defines a lightweight, consistent interface for accessing databases in PHP。
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">翻译成中文大概意思是:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MySQL扩展:在5.5.0版本中<span style="color: black;">起始</span>废弃,7.0.0版本中<span style="color: black;">已然</span>移除(<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;">MySQLI扩展:是mysql扩展的<span style="color: black;">加强</span>版</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MySQLnd:这是官方驱动,<span style="color: black;">或</span>叫做原生驱动</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PDO:PHP Data Objects,是PHP应用中的一个数据库抽象层规范</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在PHP扩展的<span style="color: black;">方向</span>上看,MYSQL和MYSQLi还是比较上层的扩展,依赖更底层的库去连接和<span style="color: black;">拜访</span>数据库。 MYSQLND <span style="color: black;">便是</span>所说的底层的数据库驱动。</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>PHP 的MYSQL<span style="color: black;">或</span>MYSQLi扩展<span style="color: black;">供给</span>的API去操作数据库。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">从底层来看,MYSQLND<span style="color: black;">供给</span>了底层和数据库交互的支持(<span style="color: black;">能够</span>简单理解为和MySQL server进行网络协议交互)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">而PDO,则<span style="color: black;">供给</span>了一个统一的API接口,使得你的PHP应用不去关心<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>PDO的API,<span style="color: black;">能够</span>在任何需要的时候无缝切换数据库服务器。<span style="color: black;">例如</span>MYSQL,SQLITE任何数据库都行。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">即从大部分功能上看,PDO<span style="color: black;">供给</span>的API接口和MYSQLI<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;">最后再贴几个php的代码,来区分几个扩展的用法:</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;">$conn = @ mysql_connect("localhost", "root", "") or die("数据库连接错误");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_select_db("bbs", $conn);</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">mysql_query("set names utf8");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "数据库连接成功";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2)mysqli连接</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$conn = mysqli_connect(localhost, root, , bbs);</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">if(!$conn){</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> die("数据库连接错误" . mysqli_connect_error());</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">else{</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo"数据库连接成功";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>?>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3)PDO连接</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">try{</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$pdo=new pdo("mysql:host=localhost;dbname=bbs","root","");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">catch(PDDException $e){</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo"数据库连接错误";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo"数据库连接成功";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">- END -</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">出品<strong style="color: blue;"> | <strong style="color: blue;"><span style="color: black;">阿铭linux</span></strong></strong></span></strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_gif/icVnCxc7lKRS6aNLKOwcv9Xgh21IRf1lVoUotkich7I7hZJMGB25K23ncq8uuLW9XZhibxRaCAJdMktrheeEsXh9g/0.gif?tp=webp&wxfrom=5&wx_lazy=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">私人<span style="color: black;">微X</span>:81677956 <strong style="color: blue;">验证:公众号</strong> </strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_jpg/ZTYjw6KickuClYWOcCteD8UYrGhbLHhCdibICiatnhdicSJLib8clf7Bs711JE4E5vSG30pPulRlXa7RfzVlIUFzQSA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">提高</span>自己,才是世界上最稳健的投资<strong style="color: blue;">。</strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_png/ZTYjw6KickuCfytkcUsEkBHMwSIMRgXZn73EhAGzlul3tNFBPWowxWEOHGfichIW29nXprcibsUzjaLQtAKQOOAXw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
我赞同你的看法,你的智慧让人佩服,谢谢分享。 回顾过去一年,是艰难的一年;展望未来,是辉煌的一年。 你的见解独到,让我受益匪浅,期待更多交流。 大势所趋,用于讽刺一些制作目的就是为了跟风玩梗,博取眼球的作品。
页:
[1]