0

I am trying to enable MySQLi, and it doesn't seem to be working. When I originally tested my code it came out with an error message that said "Fatal error: Class 'mysqli' not found in C:\Apache24\htdocs\Login-system\sql\sql_import.php on 7". I looked online to see what it meant and released that I needed to enable MySQLi.

I have removed the comment on the extension=php_mysqli.dll line in the php.ini file, this was recommended to me on multiple sites. I still get the same error message.

I have added in the code I am using below;

$host = 'localhost';
$user = 'root';
$password = 'The sloth19';

$mysqli = new mysqli($host,$user,$password);
if ($mysqli->connect_errno) {
    printf("Connection failed: %s\n", $mysqli->connect_error);
    die();
}

if ( !$mysqli->query('CREATE DATABASE accounts') ) {
    printf("Errormessage: %s\n", $mysqli->error);
}

Thanks in advance.

M.Oswald
  • 21
  • 5
  • you are missing database name in `mysqli` constructor. Checkout php site http://php.net/manual/en/mysqli.construct.php – Pankaj Makwana Jul 27 '17 at 13:58
  • 2
    you sure you have uncommented extension in right configuration file (specified in "Loaded Configuration File" of `phpinfo()`)? – ArtOsi Jul 27 '17 at 14:01
  • Possible duplicate of [Fatal error: Class 'MySQLi' not found](https://stackoverflow.com/questions/666811/fatal-error-class-mysqli-not-found) – Neodan Jul 27 '17 at 14:03
  • @PankajMakwana the DB name is optional – Phil Jul 28 '17 at 06:34

1 Answers1

1

In addition to uncommenting the php_mysqli.dll extension in php.ini, also uncomment the extension_dir directive in php.ini and specify your location:

In my case , I must set

extension_dir = "C:\xampp\php\ext"

and restart your apache24.

Ankit Singh
  • 1,477
  • 1
  • 13
  • 22
  • *"restart your apache"* <- probably the part OP was missing :) – Phil Jul 28 '17 at 06:35
  • Would the location I need to specify be for where I have my connection code saved? – M.Oswald Jul 31 '17 at 12:03
  • This is not the connection path. Read [Where to find an extension?](http://php.net/manual/en/install.pecl.windows.php#install.pecl.windows.find) for more details. – Ankit Singh Jul 31 '17 at 12:08