将此从MySQL更改为MySQLi? [英] Changing this from MySQL to MySQLi?

查看:74
本文介绍了将此从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.

请咨询旧->新功能摘要 PHP网站,并使用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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆