Fatal error: mysqli_connect()

时间秒杀一切 提交于 2019-12-04 06:54:28

问题


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?


回答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



回答2:


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());



回答3:


I guess you need to install php5-mysql.

sudo apt-get install php5-mysql

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



来源:https://stackoverflow.com/questions/15628216/fatal-error-mysqli-connect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!