-1

I'm absolutely lost here.. i've read through previous questions and answers but all i do is break the code even more.

This obviously no longer works in php7, so i'm trying (and failing) to get this to work. It's probably a slap-head for most of the folks here, but how do i get this to work in php7? Thanks.

    public function __construct() {
        $arrConfig = include './config.php';
        $this->objDB = mysql_connect($arrConfig['db']['host'],   $arrConfig['db']['username'], $arrConfig['db']['password']);
        mysql_select_db($arrConfig['db']['dbname'], $this->objDB);
    }

results in the following error.

    Fatal error: Uncaught Error: Call to undefined function mysql_connect()

cheers.

astro
  • 1
  • Possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) –  Nov 01 '18 at 07:34

1 Answers1

0

I hate to say "RFTM", but it's sound advice in this case. If yer having problems with a function, the first thing you should do is read the documentation on it.

Here they are: http://php.net/manual/en/function.mysql-connect.php

In a highlighted box at the top of the page it says this:

Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.

It then goes on to give advice of what to do instead, which is:

Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

  • mysqli_connect()
  • PDO::__construct()

Have a read of the docs, they'll steer you in the right direction. Come back and ask further questions if you get stuck on your revised solution.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78