Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,209,316 members, 8,005,625 topics. Date: Monday, 18 November 2024 at 08:31 AM |
Nairaland Forum / Science/Technology / Webmasters / Mysql Deprecated Problems (1600 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)
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: 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: |
Re: Mysql Deprecated Problems by enmacmedia: 5:55pm On Aug 08, 2015 |
Waga10: The error message you are getting is telling you to use mysqli or PHP Data Objects (PDO) The example below is with PDO;
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: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: |
Re: Mysql Deprecated Problems by micodon(m): 8:49pm On Aug 08, 2015 |
Waga10: 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" // 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: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: 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: Actually, deprecated functions will be removed entirely in future releases |
Re: Mysql Deprecated Problems by Adesege(m): 2:10am On Aug 11, 2015 |
micodon: 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: security issues as well |
(1) (Reply)
How To Make Money On Giftalworld Media Concept 2019 / Looking To Advertise For 4 Months On Nigerian Websites And Blogs / Help With Joomla Script.
(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. 39 |