Changing it from MySQL to MySQLi?

I decided to switch to MySQLi because some people told me that it is more secure. I am really confused, these are new extensions. I tried just adding "i" after each mysql, but that gave me a terrible load of errors. I looked in the PHP manual why this is happening, and there are a whole bunch of other functions. I honestly can't figure out how to convert. Can you help me?

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
source share
2 answers

Here is what you need to do:

  • Read the overview to understand the differences / benefits.

  • PHP mysqli.

  • (, ), . ( mysqli , mysql.)

+7

, MySQLi "", , , . , , . , , , ( ) , , .

$mysqli->prepare , .

http://www.php.net/manual/en/mysqli.prepare.php

+3

All Articles