-1

Our lovely domain host switched us to a new server, but didn't bother to mention that we need to upgrade all mySQL lines. :-(

We have double checked, but cannot figure out why we can connect to the DB with test code, but not with the live code. The connection works, below, but fails at the "mysqli_select_db" line below.

Can anyone help, please.

}
    }if (!(mysqli_connect(CONFIG_SQL_HOST, CONFIG_SQL_USERNAME, CONFIG_SQL_PASSWORD, CONFIG_SQL_DATABASE))) {
    exit('mySQL username/password incorrect.');
    ;
}
    if (!(mysqli_select_db(CONFIG_SQL_DATABASE))) {
        exit('mySQL Database incorrect.');
    ;*
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • The posted code can't possibly have worked before either. 1. When you connect to the database, you need to store the connection somewhere. 2. When calling [mysqli_select_db()](https://www.php.net/manual/en/mysqli.select-db.php), the first argument needs to be the connection and then the second variable should be database name. Is the actual issue that you needed to swap from `mysql_*` to `mysqli_*`? Did they upgrade from PHP 5.x to PHP 7.x? If that's the case, then you need to read the manual. `mysql_*` (removed in PHP 7) and `mysqli_*` does not work the same way. – M. Eriksson Sep 20 '20 at 11:53
  • Magnus,yes, that code has worked for the last 12 years, with no changes, until the Host moved the domain from PHP 5.x to PHP 7.x. I have no idea as to why it doesn't work and as mentioned below, I'm a newbie. :-( – user3553376 Sep 20 '20 at 11:56
  • 1
    Then it was about time they upgraded. PHP 5.6 hasn't been supported for over 1,5 years. You need to start reading the manual about how to use mysqli, (or PDO, which I think is way easier to use). You're in for a full refactoring to replace the old `mysql_*`-api from your code. There are tons of examples in the manual about both mysqli and pdo. – M. Eriksson Sep 20 '20 at 11:57

1 Answers1

-1

First try to know the reason. $conn = new mysqli(CONFIG_SQL_HOST, CONFIG_SQL_USERNAME, CONFIG_SQL_PASSWORD, CONFIG_SQL_DATABASE)

if ($conn->connect_errno) {echo "MySQLError " . $conn->connect_errno . " " . $mysqli->connect_error;exit(0); }

LCJ1st
  • 1
  • 1