1

We're currently hosting with LCN and have got a database which everything works fine, its basically an app that calls scripts on the host which login to a database using:

class DB{
private $dbHost     = "huya.uksrv.co.uk";
private $dbUsername = "uname";
private $dbPassword = "pword";
private $dbName     = "dbase";



public function __construct(){
    if(!isset($this->db)){
        // Connect to the database
        $conn = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName, 2083);
        if($conn->connect_error){
            die("Failed to connect with MySQL: " . $conn->connect_error);
        }else{
            $this->db = $conn;
        }
    }
}

Getting the error: Failed to connect with MySQL: MySQL server has gone away

The problem is, were changing hosting to cPanel and their database is a little different to what I'm used to, it doesn't give a normal login page ie:

https://www.mydbadmin.co.uk/index.php its now: https://huya.uksrv.co.uk:2083/3rdparty/index.php

I'm able to login to the database through cPanel and create tables etc, but I can run a script which normally would work fine on the other server.

I believe the problem is something to do with localhost and sockets but ive no clue how these work at all.

The new Database details are:

Server: Localhost via UNIX socket
Server type: MariaDB
Server connection: SSL is not being used Documentation
Server version: 10.3.24-MariaDB-log-cll-lve - MariaDB Server
Protocol version: 10
User: xxxxxxxxxxxxxx@localhost
Server charset: cp1252 West European (latin1)

The old Database details are:

Server: database.lcn.com via TCP/IP
Server type: MySQL
Server connection: SSL is not being used Documentation
Server version: 5.7.29-log - MySQL Community Server (GPL)
Protocol version: 10
User: xxxxxxxxxx@xxxx.namesco.net
Server charset: UTF-8 Unicode (utf8)

How can I modify the class DB{} code to connect to the new database? Is it possible as I know the old server was TCP/IP.

  • I'm not sure I understand but you are already connecting via TCP/IP. I can see you have a domain name specified, which I would assume translates to an IP address. Am I wrong? – Dharman Sep 26 '20 at 16:11
  • You need to stop manually checking for errors. Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) and [Should I manually check for errors when calling “mysqli_stmt_prepare”?](https://stackoverflow.com/q/62216426/1839439) – Dharman Sep 26 '20 at 16:13
  • That's the working script from the other server, my problem is I'm not sure what to replace dbHost with. I've tried https://huya.uksrv.co.uk:2083/3rdparty/index.php but getting "MySQL server has gone away" error – Ben Cassell Sep 26 '20 at 16:18
  • It should be just your domain name e.g. `huya.uksrv.co.uk`. Port number goes separately in the fifth argument. See https://www.php.net/manual/en/mysqli.construct.php – Dharman Sep 26 '20 at 16:20
  • @Dharman yes I've also tried port number in 5th argument but still nothing :/ – Ben Cassell Sep 26 '20 at 17:02
  • Update the question and show us how you change that class. Only remove username and password leave the rest as is. – Dharman Sep 26 '20 at 17:04
  • @Dharman ive edited the class to show how I'm trying to access db, ill change the checking for errors once i know its working – Ben Cassell Sep 26 '20 at 17:12
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222123/discussion-between-dharman-and-ben-cassell). – Dharman Sep 26 '20 at 17:18
  • just an idea, but if your bind address in my,cnf ( `/etc/my.cnf` ) is hard set to local (`bind-address=127.0.0.1`) then you will not be able to remotely access the MySQL at all, regardless of ports or other criteria. Solution, empty bind-address or set it to `bind-address=*` and restart MySQL. – Martin Sep 26 '20 at 17:41

1 Answers1

0

It was just:

private $dbHost     = "localhost";
private $dbUsername = "uname";
private $dbPassword = "pword";
private $dbName     = "dbase";

Thankyou to those who help in the chat :D