Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deprecated: mysql_connect()

    Hi,

    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:
    Code:
    $link = mysql_connect($hostname, $username, $password)
    or die ("Server Connection Error".mysql_error());
    mysql_select_db($database)
    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.
    Anthony

  2. #2
    Regular Coder Vege's Avatar
    Join Date
    Jan 2008
    Posts
    928
    Thanks
    22
    Thanked 123 Times in 122 Posts
    Most people here recommends PDO over mysqli.
    https://phpdelusions.net/pdo

    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
    Location
    Keene, NH
    Posts
    2,791
    Thanks
    3
    Thanked 402 Times in 391 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!
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com


 

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
  •