-2

I know there are quite a few forums out there talking about this problem in stackoverflow but none seem helped so....trying to see if anyone else can give me a hand...

I installed mysql server 5.1 and no error happens during the installation so I assume everything is fine but when I'm learning and trying to use php and to connect through mysql and there is this error message saying

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\books.php on line 3

My codes are here

<?php

$db = mysqli_connect("localhost", "root", "3308") or die(mysqli_connect_error());

mysqli_select_db($db, "booksdb") or die(mysqli_error($db));

mysqli_query($db, "CREATE TABLE books(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR(64) NOT NULL)") or die(mysqli_error($db));

mysqli_query($db, "INSERT INTO books(id, title) VALUES(NULL, 'the nose')") or die(mysqli_error());

mysqli_query($db, "INSERT INTO books(id, title) VALUES(NULL, 'the overcoat')") or die(mysqli_error());

mysqli_query($db, "INSERT INTO books(id, title) VALUES(NULL, 'war and peace')") or die(mysqli_error());

$result = mysqli_query($db, "SELECT id, title FROM books") or die(mysqli_error());

while($record = mysqli_fetch_assoc($result)){
    echo $record['id'];
    echo " ";
    echo $record['title'];
    echo "<hr/>";
}


?>

in my php.ini file I did uncomment both

extension=php_mysql.dll
extension=php_mysqli.dll

and of course restarted apache. Also restarted the who machine too but that error message keeps on coming up and I have no idea how to fix it. I searched a few forums and they all asked to make sure the extension is uncommented which they are. Also checked few forum sites and tried some. Some I didn't understand what they were telling me to try but the one I tried, none of them worked. Any ideas here?

aynber
  • 22,380
  • 8
  • 50
  • 63
Dora
  • 6,776
  • 14
  • 51
  • 99

3 Answers3

1

Okay, this might be an alternate solution to the problem you are facing. Not exactly an answer, though. You need to have php_mysqli.dll and other extensions in the right place. You need to check in three areas:

  1. The physical file php_mysqli.dll existence in the ext folder.
  2. Whether the directory ext is correctly referenced.
  3. Check if Apache has access and permissions to the folder.
  4. Check if you have edited the right file. There might be more than one php.ini files.

Another simple solution would be installing a package like those below:

  1. WAMP Server (I recommend this for small and also may be for live projects)
  2. XAMPP
  3. USB Web Server
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

1) Make sure that php_mysqli.dll is present in your directory. 2) Does your id auto_increment? If yes, then you dont have to insert it to your table. Check your syntax. Try this:

mysqli_query($db, "INSERT INTO books(title) VALUES('the nose')") or die(mysqli_error());
Mark
  • 8,046
  • 15
  • 48
  • 78
0

I guess you need to install php5-mysql.

sudo apt-get install php5-mysql

And restart your apache server, and it should work fine.

Optimus Prime
  • 6,817
  • 5
  • 32
  • 60