I am getting this warning, but the program still runs correctly.
The MySQL code is showing me a message in PHP:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\task\media\new\connect.inc.php on line 2
My connect.inc.php
page is
<?php $connect = mysql_connect('localhost','root',''); mysql_select_db('dbname'); ?>
What does this mean and how can I eliminate the message?
This extension was deprecated in PHP 5.5. 0, and it was removed in PHP 7.0.
mysql_connect() establishes a connection to a MySQL server. The following defaults are assumed for missing optional parameters: server = 'localhost:3306', username = name of the user that owns the server process and password = empty password. The server parameter can also include a port number.
The mysqli_connect() function in PHP is used to connect you to the database. In the previous version of the connection mysql_connect() was used for connection and then there comes mysqli_connect() where i means improved version of connection and is more secure than mysql_connect().
It's still available in 5.6.
There are a few solutions to your problem.
The way with MySQLi would be like this:
<?php $connection = mysqli_connect('localhost', 'username', 'password', 'database');
To run database queries is also simple and nearly identical with the old way:
<?php // Old way mysql_query('CREATE TEMPORARY TABLE `table`', $connection); // New way mysqli_query($connection, 'CREATE TEMPORARY TABLE `table`');
Turn off all deprecated warnings including them from mysql_*:
<?php error_reporting(E_ALL ^ E_DEPRECATED);
The Exact file and line location which needs to be replaced is "/System/Startup.php > line: 2 " error_reporting(E_All); replace with error_reporting(E_ALL ^ E_DEPRECATED);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With