0

I am having to update MySQL to mysqli as my host is upgrading to PHP5.6

I have managed to convert and connect to the database as below

 $link_id = mysql_connect("$db_host","$db_user","$db_password");
 if (mysql_select_db("$db_database", $link_id));
 else
 {
         echo "connection failed.";
 }

converted to

$link_id = mysqli_connect("$db_host","$db_user","$db_password","$db_database");
if ($mysqli->connect_errno) {
  echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

I cannot get the fetch results to work, can anyone help me convert the following code

$results = mysql_query("$select", $link_id);
while ($query_data = mysql_fetch_row($results))
{

Many Thanks

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • There is a bug in the `if ` in the first snippet. There is a semicolon after the condition that shouldn't be there. – GolezTrol Jul 19 '15 at 10:03
  • Another issue, in the second snippet, is that you are mixing the procedural style and the object oriented style of using `mysqli`. It's better to stick with one of them. Choosing the procedural style is certainly easier while you are in the process of migrating. – GolezTrol Jul 19 '15 at 10:06
  • @John Kilbey which hosting you are using? – Shehary Jul 19 '15 at 10:19
  • thanks, I need this bit converting and don't understand procedural style, newbie to mysqli $results = mysql_query("$select", $link_id); while ($query_data = mysql_fetch_row($results)) { – John Kilbey Jul 19 '15 at 11:47

0 Answers0