admin 发表于 2020-11-22 14:44:26

mysqli_query()与mysql_query()的区别,PHP升级后mysql_query()的应用...


<p>PHP升级到5.6以上后,就不再支持mysql_query()此类的用法了,只能用mysqli_query.而mysqli_query()与mysql_query()的区别还挺大,绝不是简单的加个i替换一下那么简单。现在也在学习过程中,先记录区别如下:</p><p>一、mysqli_query($conn,"select * from table")这样的语句中,$conn是必需的如果 没有就报错,而mysql中是可选项不是必需项。</p><p>二、这个$conn,你如果是在函数中产生的,那在函数之外是无法被调用的,会报错,必须在函数中将它定义为全局参数,才可以被任意调用。比如&nbsp;&nbsp;$GLOBALS['conn']=$conn;这样就不会报错了。</p><p><span style="color: rgb(51, 51, 51); font-family: &quot;noto sans cjk sc&quot;, &quot;pingfang sc&quot;, &quot;microsoft yahei&quot;, &quot;hiragino sans gb&quot;, sans-serif;">尊重知识产权,转载请注明并复制本段,一元复始技术论坛原创</span><a href="http://www.1rmb.net/" target="_blank" title="一元复始技术论坛" style="font-family: &quot;noto sans cjk sc&quot;, &quot;pingfang sc&quot;, &quot;microsoft yahei&quot;, &quot;hiragino sans gb&quot;, sans-serif;">http://www.1rmb.net</a><span style="color: rgb(51, 51, 51); font-family: &quot;noto sans cjk sc&quot;, &quot;pingfang sc&quot;, &quot;microsoft yahei&quot;, &quot;hiragino sans gb&quot;, sans-serif;">.</span><br></p><p>一般会报的错误为:<a target="_blank" class="title" href="https://blog.csdn.net/TAOLWZH/article/details/78834065" title="Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /var/www/html/php..解决方案_PHP_汪汪的博客-CSDN博客" style="margin: 0px; padding: 0px; list-style: none; color: black; font-family: &quot;Segoe UI&quot;, Tahoma, Geneva, Verdana, 微软雅黑; font-size: 13px; font-variant-numeric: normal; font-variant-east-asian: normal; line-height: 20px; white-space: nowrap;"><font face="Segoe UI, Tahoma, Geneva, Verdana, 微软雅黑"><span style="list-style: none; font-size: 13px; line-height: 20px; white-space: nowrap;">Warning: mysqli_query() expects parameter 1 to be mysqli, null given in</span></font><span class="Apple-converted-space" style="margin: 0px; padding: 0px; list-style: none; color: black; font-family: &quot;Segoe UI&quot;, Tahoma, Geneva, Verdana, 微软雅黑; font-size: 13px; font-variant-numeric: normal; font-variant-east-asian: normal; line-height: 20px; white-space: nowrap;">&nbsp;</span></a>,缺少参数。</p>
页: [1]
查看完整版本: mysqli_query()与mysql_query()的区别,PHP升级后mysql_query()的应用...