1

I wanna use mysqli database connection inside my own websocket server. How can i use the database without defining the unix socket path? Like this: $connection = new mysqli($db_servername, $db_username, $db_password, $db_name,3306,'/Applications/MAMP/tmp/mysql/mysql.sock');

The webSocket server is running on localhost:8080. I also tried some other ports and hostnames but i got stil the same error: Fatal error: Uncaught Error: Class 'mysqli' not found in D:\project\

$this->socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($this->socketResource, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($this->socketResource, 0, $this->port);
socket_listen($this->socketResource);
public function connectToDatabase(){
      $db_servername = "localhost";
      $db_username = "root";
      $db_password = "root";
      $db_name = "dbname";

      // Create connection
      $connection = new mysqli($db_servername, $db_username, $db_password, $db_name);
      return $connection;
    }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Carpiee
  • 19
  • 1
  • 5

1 Answers1

0

The error is that the class doesn't exist, which you don't have the mysqli extension installed. The manual

Personally I don't use Windows but if I remember correctly you should go to your php.ini file and uncomment the line extension=mysqli. (I don't know if this is the actual name but doing a mysqli search should get you where you have be.). The binaries are usually already installed on Windows, but if they aren't you should be able to find a downloadable from the PHP manual.

Jelly Legend
  • 201
  • 1
  • 5