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?
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
