I am getting this warning, but the program still runs correctly.
The MySQL code is showing me a message in PHP:
Deprecated: mysql_connect(): T
You can remove the warning by adding a '@' before the mysql_connect.
@mysql_connect('localhost','root','');
but as the warning is telling you, use mysqli or PDO since the mysql extension will be removed in the future.
The mysql_*
functions has been deprecated as of 5.5.0
Source
PDO class replaces these methods. Example for Mysql or MariaDB :
$BDD_SQL = new PDO('mysql:host='.BDD_SQL_SERVER.';dbname='.BDD_SQL_BASE.';charset=utf8',
BDD_SQL_LOGIN, BDD_SQL_PWD,
array(
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //launch exception if error
PDO::ATTR_DEFAULT_FETCH_MODE=> PDO::FETCH_ASSOC
));
Source : PDO Class
If you have done your coding then
ini_set("error_reporting", E_ALL & ~E_DEPRECATED);
is good option but if you are in beginning then definitely you should use mysqli.
To suppress the deprecation message for this alone (and stay informed of other deprecations in your code) you can prefix the connect with @:
<?php
$connect = @mysql_connect('localhost','root','');
mysql_select_db('dbname');
?>
mysql_*, is officially deprecated as of PHP v5.5.0 and will be removed in the future.
Use mysqli_* function or pdo
Read Oracle Converting to MySQLi