0

I want to connect php 8 to connect mysql database. php is running on inbuilt server and mysql is running on xampp. I am getting error i.e. connect mysql with php in-built server. Error: Uncaught Error: Call to undefined function mysqli_connect().

My php code is :

    $host = "127.0.0.1:3306";
    $user = "root";
    $password = "";
    $db = "company";
    $conn  = mysqli_connect($host, $user, $password, $db);
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

Php command I am using for running inbuilt server

    php -S localhost:4000
 

xampp control panel

Sowmiya
  • 59
  • 8
  • Can you try to remove the port (:3306) from the host parameter, as it is not supported in this parameter and 3306 is the standard port. If you need to specify a port, it is a seperate parameter after the DB, as you can read [here](https://www.php.net/manual/en/mysqli.construct.php) Edit: Didn't see, that your error was a different one. It seems that the PHP extension for mysql connections isn't installed. Install this extension, so then it should work. – stui Nov 27 '21 at 13:22
  • I did that also. but still I am getting error. – Sowmiya Nov 27 '21 at 13:25
  • ___Small Note___ If you are using `php -S localhost:4000` then you are not actually using the Apache in XAMPP at all. But as you have it, why not use it – RiggsFolly Nov 27 '21 at 13:39
  • When I am using xampp's apache server for php , it is working fine. I want to know how to connect php inbuilt server with xampp mysql database. I am just learning php. so that I want to know about ways of connecting php's inbuilt sever with database. – Sowmiya Nov 27 '21 at 13:56
  • Read this article http://www.dwuser.com/education/content/why-you-need-a-testing-server-and-how-to-do-it/ –  Nov 27 '21 at 14:18
  • With php's inbuilt server I couldn't able to connect? – Sowmiya Nov 27 '21 at 14:39
  • I refer this link. https://stackoverflow.com/a/35425511/15375315. I tried this one. I enable mysqli extension. But still I am getting error. – Sowmiya Nov 27 '21 at 16:51

0 Answers0