Link to home
Start Free TrialLog in
Avatar of dkilby
dkilbyFlag for Canada

asked on

PHP5 to PHP7 DatabaseConnection

I am look at an old PHP project that uses mysql_connect, and I am trying to update it to PHP 7, by using mysqli_connect.

In the original project, I had a file - connect.php which had the database info, I would then include that file where needed.  But I cant seem to get this to work in PHP7

Original file looked like this.

 <?php
// Connects to my Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
?>

I have changed to this

<?php

$con=mysqli_connect("your.hostaddress.com", "username", "password","Database_Name");

?>

now on  a page where I had

return mysql_real_escape_string($data);

and am now trying to use

return mysqli_real_escape_string($con, $data);

and I get the error con is not defined.

How can i keep the original structure but update to PHP7
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial