dkilby
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.hostad dress.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. hostaddres s.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
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.hostad
mysql_select_db("Database_
?>
I have changed to this
<?php
$con=mysqli_connect("your.
?>
now on a page where I had
return mysql_real_escape_string($
and am now trying to use
return mysqli_real_escape_string(
and I get the error con is not defined.
How can i keep the original structure but update to PHP7
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.