-1

I have spent the last 2 hours trying to solve this problem. I keep getting this error when trying to connect my php script with mySqli that is all hosted on a WAMP local host.

https://pastebin.com/HrJsnspG

;extension_dir = "./"
; On windows:
extension_dir = "C:\PHP7\ext"

I have added my pastebin above that shows my php.ini file. I changed the extensions as people have suggested on stack overflow and removed the ';' but nothing has worked, i still get the error. I have also reinstalled my WAMP server.

Any further suggestions?

<?php

  $servername = "localhost";
  $username = "root";
  $password = "";

  //create connection
  $conn = new sqli($servername, $username, $password);

  //check fann_get_total_connections
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  }
  echo "Connected Successfully";
?>
Jordan
  • 7
  • 1
  • 7

1 Answers1

1

To connect properly with MySQLi you need to create an instance of mysqli class, enable error reporting and set the correct charset.

<?php

// Connection code
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$conn = new \mysqli('localhost', 'testuser', 'password', 'dbname');
$conn->set_charset('utf8mb4');

For more information see https://phpdelusions.net/mysqli/mysqli_connect#oop

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • im still getting the same error. Within my index, I have included "phpConnect.php"; //My php file that connects to sql. – Jordan Nov 25 '19 at 12:59