1
My code:
<?php
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysqli_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
To solve superficially I saw that putting a @ in front of my_sql_connect would work.
// Connecting to mysql database
$con = @mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysqli_error());
But I see that soon will become obsolete, as would the code with my_sqli?
If there is no canonical answer to this, it should exist. Surely there are several questions that have already answered this.
– Maniero
Migrate from mysql to mysqi?
– rray
How to convert a MYSQL connection to MYSQLI? and Why should we not use mysql type functions_*?
– rray
I’m sure I’ve been looking into this, and unfortunately I haven’t found anything that works for me. I read that practically it was only change what was written with my_sql to my_sqli, but the error in the parameters.
– Matheus Castro
Syntax changes, for all functions mysqli_*(procedural mode) the first argument is always the connection.
– rray
The coolest of this question is that by putting a @ solves the problem: http://answall.com/q/50166/101
– Maniero
Would it be OK to leave @ Since it works, but it would be a problem in the future?
– Matheus Castro
@bigown Just to clarify: does not solve the problem. Before PHP 7, no errors appear about the functions
mysql_*
, only warnings or warnings. The@
serves only to say "do not show warnings for functions prefixed with @". To not show errors one can resort toini_set('display_errors', 'Off'); error_reporting(E_ALL);
– StillBuggin
@Eduardoalmeida you don’t understand the joke
– Maniero
@bigown Sorry!
– StillBuggin