Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,253 members, 7,815,379 topics. Date: Thursday, 02 May 2024 at 11:27 AM

Mysql Deprecated Problems - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Mysql Deprecated Problems (1545 Views)

Creating Any Type Of System Management From Scratch With Php And Mysql / Ask Questions On Website Development (HTML, Jquery, Javascript, PHP, Mysql) Etc. / Amazing Ebooks!!! On Website Design, Php/mysql And Graphics For N3,500 Only!!! (2) (3) (4)

(1) (Reply) (Go Down)

Mysql Deprecated Problems by Waga10: 4:19pm On Aug 08, 2015
i keep getting this message in my website since i migrated my new host{Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u666995223/public_html/dbconfig.php on line 9}
please if anybody knows the solution for this help out so i can put my website back online thanks.
Re: Mysql Deprecated Problems by micodon(m): 4:38pm On Aug 08, 2015
Waga10:
i keep getting this message in my website since i migrated my new host{Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u666995223/public_html/dbconfig.php on line 9}
please if anybody knows the solution for this help out so i can put my website back online thanks.

PHP's mysql driver is no longer supported as from PHP 5.5. mayber your new host is running that or above. You should rewrite your queries using mysqli or PDO
Re: Mysql Deprecated Problems by Vicben(m): 4:54pm On Aug 08, 2015
Google search will direct on the right codes to connect to your database through MySqli
Re: Mysql Deprecated Problems by Waga10: 5:42pm On Aug 08, 2015
if you can help me with somthing like this [<?php
//
$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";[b][/b]

//
$dbconnect=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
?>] it will be much appreciated
thanks
micodon:


PHP's mysql driver is no longer supported as from PHP 5.5. mayber your new host is running that or above. You should rewrite your queries using mysqli or PDO
Re: Mysql Deprecated Problems by enmacmedia: 5:55pm On Aug 08, 2015
Waga10:
if you can help me with somthing like this [<?php
//
$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";

//
$dbconnect=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
?>] it will be much appreciated
thanks

The error message you are getting is telling you to use mysqli or PHP Data Objects (PDO) The example below is with PDO;

// Connecting to database
$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";

try {
$db_connection = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname . ';charset=utf8', $dbuser, $dbpass);
}

catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}

The above code will help you connect to you database if the variables provided are correct or else it will display an error message. Do more research on PHP Data Objects, so that you'll know how to run mysql queries using PHP Data Objects (PDO).
Re: Mysql Deprecated Problems by Waga10: 6:10pm On Aug 08, 2015
enmacmedia:


The error message you are getting is telling you to use mysqli or PHP Data Objects (PDO) The example below is with PDO;

// Connecting to database
$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";

try {
$db_connection = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname . ';charset=utf8', $dbuser, $dbpass);
}

catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}

The above code will help you connect to you database if the variables provided are correct or else it will display an error message. Do more research on PHP Data Objects, so that you'll know how to run mysql queries using PHP Data Objects (PDO).
this is exactly what i am using before but here in the new host, it will display a single line of some deprecated mysql error
Re: Mysql Deprecated Problems by bassdow: 7:23pm On Aug 08, 2015
There are 2 ways to fix that error. Either rewrite your code to reflect the changes in the latest versions of PHP (which is recommended) OR just look for another host with an outdated version of PHP. I would suggest you rewrite your code now because even if you go for the second option which is looking for a host with outdated PHP version. you never can tell what would happen tomorrow.
You can temporarily use option 2 until option 1 is ready.
Re: Mysql Deprecated Problems by micodon(m): 8:48pm On Aug 08, 2015
Waga10:
if you can help me with somthing like this [<?php
//
$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";[b][/b]

//
$dbconnect=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
?>] it will be much appreciated
thanks



Re: Mysql Deprecated Problems by micodon(m): 8:49pm On Aug 08, 2015
Waga10:
if you can help me with somthing like this [<?php
//
$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";[b][/b]

//
$dbconnect=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
?>] it will be much appreciated
thanks




use mysqli_connect
Re: Mysql Deprecated Problems by Vicben(m): 9:39pm On Aug 08, 2015
This is how you can connect with MySqli

<?php
$con=mysqli_connect("localhost","my_user","
my_password","my_db"wink;
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
Re: Mysql Deprecated Problems by ps3o(m): 11:45pm On Aug 08, 2015
use mysqli_connect in place of mysql_connect. some platforms may require u to change all where u particularly used mysql to mysqli. just do it and save yourself from the issue
Re: Mysql Deprecated Problems by Vinshu(f): 2:53am On Aug 09, 2015
You need to rewrite your entire script to Mysqli you cannot change only the connection file to MysqlI or PDO and leave the rest as mysql_ You will encounter errors! Your host should have "Silenced Deprecated Error" which would hide those warnings and probably allow mysql_ to connect and work just fine!

use error_reporting(0);
Re: Mysql Deprecated Problems by Youngzedd(m): 7:33am On Aug 09, 2015
Disable error reporting then.
Re: Mysql Deprecated Problems by Waga10: 12:48pm On Aug 09, 2015
ok thanks all for the suggestions, let me try mysqli or pdo as the error reffers to that
Re: Mysql Deprecated Problems by Waga10: 1:22pm On Aug 09, 2015
finally solved.
<?php

$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";

//Don't change the below 2 lines
$dbconnect=@mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
php?>

the above solved the problem. just put @ at the back of mysql
soursce
http://stackoverflow.com/users/3233927/rebirth
Re: Mysql Deprecated Problems by DualCore1: 4:13pm On Aug 09, 2015
Waga10:
finally solved.
<?php

$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";

//Don't change the below 2 lines
$dbconnect=@mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
php?>
the above solved the problem. just put @ at the back of mysql
soursce
http://stackoverflow.com/users/3233927/rebirth
You have just applied first aid to an injured script. If no real treatment is given, your script will end up with cancer in the near future. Learn PDO.
Re: Mysql Deprecated Problems by micodon(m): 11:05pm On Aug 09, 2015
Waga10:
finally solved.
<?php

$dbhost="mysql.host.com";
$dbname="12345";
$dbuser="12345";
$dbpass="123456";

//Don't change the below 2 lines
$dbconnect=@mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
php?>

the above solved the problem. just put @ at the back of mysql
soursce
http://stackoverflow.com/users/3233927/rebirth

Bros you are just suppressing errors with '@'. it doesn't remove the problem, it only hides the errors. when the host upgrades to a version of PHP that has removed the mysql library, this script will fail without showing errors. This solution is extremely bad. Use PDO or Mysqli
Re: Mysql Deprecated Problems by Adesege(m): 7:24am On Aug 10, 2015
Waga10, while that may solve your problem, technically it is wrong to do so.

Mysql has been deprecated as of PHP 5.5 does not mean you cant use it on a server. Deprecated doesnt mean it has been removed.

The solution you got will suppress the error but what if you have a problem connecting ro your db, that means you wont be able to get the errors.

A more better approach is to suppress E_DEPRECATED errors using the php error reporting. With that, you will get every other errors expect for E_DEPRECATED errors.

Put this at the very top of your mysql_connect page.

<?php
error_reporting(E_ALL ^E_DEPRECATED);
?>

As a side note, it is advisable you migrate to mysqli or PDO. There is a tool you can use to migrate from mysql to mysqli online. You can check mysql official website.

Let me know if you get it
Re: Mysql Deprecated Problems by micodon(m): 10:45am On Aug 10, 2015
Adesege:
Waga10, while that may solve your problem, technically it is wrong to do so.

Mysql has been deprecated as of PHP 5.5 does not mean you cant use it on a server. Deprecated doesnt mean it has been removed.

The solution you got will suppress the error but what if you have a problem connecting ro your db, that means you wont be able to get the errors.

A more better approach is to suppress E_DEPRECATED errors using the php error reporting. With that, you will get every other errors expect for E_DEPRECATED errors.

Put this at the very top of your mysql_connect page.

<?php
error_reporting(E_ALL ^E_DEPRECATED);
?>

As a side note, it is advisable you migrate to mysqli or PDO. There is a tool you can use to migrate from mysql to mysqli online. You can check mysql official website.

Let me know if you get it

Actually, deprecated functions will be removed entirely in future releases
Re: Mysql Deprecated Problems by Adesege(m): 2:10am On Aug 11, 2015
micodon:


Actually, deprecated functions will be removed entirely in future releases


Yah! Buh it's yet to be removed. So it can still be used. Just that he will be having cross platform issues
Re: Mysql Deprecated Problems by Waga10: 8:01pm On Aug 12, 2015
i do not understand wverything you guys are saying because, i am not use in coding, i still use that @ but have not publish the site online, so how can any one help me on how best to solve this deprecated issue,when i use the edrprciate it will refer me to config.php as an error so am iost of idea on how to fix it
Re: Mysql Deprecated Problems by 0luwatope(m): 6:46am On Aug 13, 2015
Am on a php 5.4 and am still using mysql and am going to rewrite my sql connections sooner or later but today, i wrote a particular pdo query for one cron job like that, i'll recommend you to use PDO, its not that easy to understand but its highly recommended than mysqli
Re: Mysql Deprecated Problems by micodon(m): 9:23am On Aug 13, 2015
Adesege:


Yah! Buh it's yet to be removed. So it can still be used. Just that he will be having cross platform issues

security issues as well

(1) (Reply)

A Guide On SEO Audits For SEO Companies In Nigeria / How To Save 30% Of Your Mobile Data Usage Using Datally / How To Make Money On Giftalworld Media Concept 2019

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 47
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.