Changing this from MySQL to MySQLi?(将其从 MySQL 更改为 MySQLi?)
问题描述
我决定改用 MySQLi,因为有人告诉我它更安全.我真正感到困惑的是新的扩展.我尝试在每个 mysql 之后添加 'i',但这给了我一大堆错误.我在 PHP 手册中查找了为什么会发生这种情况,还有一大堆其他功能.老实说,我不知道如何转换.你能帮我吗?
I've decided to switch to MySQLi, because some people have told me it's more secure.. What I'm really confused about, is the new extensions. I tried just added 'i' after every mysql, but that gave me a crap load of errors. I looked up in the PHP manual why that was happening and there was a whole bunch of other functions.. I honestly can't figure out how to convert. Can you help me out?
include("dbinfo.php");
mysql_connect($c_host,$c_username,$c_password);
@mysql_select_db($c_database) or die(mysql_error());
$mycon = new mysqli($c_host, $c_username, $c_password, $c_database);
$query="SELECT * FROM users WHERE username='" .$_COOKIE['username']. "'";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_numrows($result);
$username=mysql_result($result,$i,"username");
推荐答案
以下是您需要做的:
阅读概述,以便了解差异/优势.
Read the overview so that have an understanding of the differences/advantages.
查阅old -> new function summaryPHP 站点并使用 mysqli 接口启动和运行现有代码.
Consult the old -> new function summary on the PHP site and get your existing code up and running with the mysqli interface.
利用改进(例如使用准备好的语句) 否则这是徒劳的.(默认情况下,mysqli 确实并不比 mysql 更安全.)
Take advantage of the improvements (such as using prepared statements) otherwise this is a futile exercise. (By default mysqli really isn't any more secure than mysql.)
这篇关于将其从 MySQL 更改为 MySQLi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将其从 MySQL 更改为 MySQLi?
基础教程推荐
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01