Quantcast
Channel: How do I convert a script using mysql_ functions to use mysqli_ functions? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

How do I convert a script using mysql_ functions to use mysqli_ functions?

$
0
0

EDIT: Whether or not to use mysqli_ is outside the scope of this question. Consider using PDO.


What steps need to be taken to convert a script from using the deprecated mysql_ functions to mysqli_?

Is there anything that needs to be done differently when using mysqli_ instead of mysql?

Here's a basic script using mysql_ functions:

<?php//define host, username and password$con = mysql_connect($host,$username,$password);if (!$con) {    die('Could not connect: ' . mysql_error());}$db_name ="db1";mysql_select_db($dbname, $con);$value1 = mysql_real_escape_string($input_string);$query = 'SELECT * FROM table1 WHERE table1.col1=' . $value1 . '';$result = mysql_query($query, $con);while($row = mysql_fetch_assoc*$result){    $col1 = $row['col1'];    $col2 = $row['col2'];    echo $col1 . '' . $col2 . '<br />';}mysql_close($con);?>

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images