本文介绍了将其从 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");

推荐答案

以下是您需要做的:

  1. 阅读概述,以便了解差异/优势.

  1. 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:31