Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2018
    Thanked 0 Times in 0 Posts

    Deprecated: mysql_connect()


    Firstly hope this is the right place..

    I'm getting depreciated errors after updating the php version to 5.6 and was hoping someone could help.
    I'm currently using this code:
    $link = mysql_connect($hostname, $username, $password)
    or die ("Server Connection Error".mysql_error());
    or die ("Database Connect Error ".mysql_error());
    I did some searching and seems I need to use mysqli but I couldn't get it to work.

    Any help is greatly appreciated.

  2. #2
    Regular Coder Vege's Avatar
    Join Date
    Jan 2008
    Thanked 132 Times in 131 Posts
    Most people here recommends PDO over mysqli.

    If you are in a hurry you can suppress the deprecated errors and the webpage will still function.

  3. #3
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Keene, NH
    Thanked 455 Times in 444 Posts
    Yes, as of PHP 5.6 you will get warnings about mysqli -- but if you're "upgrading" to 5.6 you're not upgrading, your security patching and not much else. PHP 7 would be the ACTUAL upgrade and in that you're not going to get a warning, your code flat out will not run as mysql_ functions no longer exist.

    If you want to run 5.6/later you HAVE to rewrite your ENTIRE codebase to modern methodology. MORE than that it's not going to be as simple as swapping mysql_ for mysqli_ as technique like prepare/execute should also be used to replace the outdated outmoded halfwitted "slopping of variables into query strings" garbage that should NEVER have existed in PHP in the first place.

    ... and yeah, I would suggest you use PDO instead of mysqli, and YEAH that means you've got a lot to learn and even more code to rewrite to drag your program kicking and screaming out of the 1990's SQL mentality. *[i]'more emphasis'[i]* on the 'mental'.

    Pretty much anyplace you have "mysql_" in your code needs to be rewritten from scratch -- if for no other reason than security alone... and no, creating polyfill wrappers is NOT the damned answer! It's scary how many people do that!
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts