PHP and MySQL connection cannot use mysqli extension problem
Super木
Super木 2019-03-30 15:12:34
0
4
1468

$link=@mysqli_connect('localhost','root','root')|| die('Database connection error');

//This step can realize the connection

$sql='set names utf8';

$result=mysqli_query($link,$sql);

var_dump($result);

//This step Unable to use mysqli extension, warning: Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in D:\360Downloads\Software\phpStudy\WWW\link.php on line 13
NULL

PHP version is php-5.4.45, the corresponding php.ini file has also been modified and added. Mysqli can be found in phpinfo.php

There are two tables in the itsource database used, one students and one classes , there are two pieces of data in the table

mysql> select * from classes;

------ ----------- ------ -----

| id | classname | classroom |

------ ----------- --------- --

| NULL | php2019 | 417 |

| 2 | html52018 | 520 |

------ ---------- - -----------

2 rows in set (0.00 sec)


##mysql> select * from student;

------ ---------- ------

| id | username | age |

----- - ---------- ------

| NULL | Zhang San | 24 |

| 2 | Wang Wu | 20 |

------ ---------- ------

2 rows in set (0.00 sec)

What is the cause?

Super木
Super木

reply all(2)
angryTom

It may be a problem with the higher version of php

秋香姐家的小书童

The first step is to open the folder where you put php and you will see a folder called ext. This folder stores various extensions of php including the mysqli extension (check whether there is a php_mysqli.dll file in the ext folder , if not, please go to the php official website to download php), if so, use an editor to open php.ini in the php directory (this is the configuration file of Php, the copied php.ini-development file, and then rename it to php. ini) Open it with an editor and search for ;extension=php_mysqli.dll (only one will be found in the file) and then remove the beginning; (semicolon) to make the extension effective. (If you want to open other extensions, also search for ;extension=*** and remove the previous; (semicolon) to make it effective) Attention! ! ! ! ! ! ! If there is a php_mysqli.dll extension in the ext folder but cannot be found in the configuration file php.ini; extension=php_mysqli.dll can be added manually (be careful not to include a semicolon). If it still doesn't work, download a new php


After all configuration changes, you need to restart apache for the configuration to take effect. The restart method is windows + r, then enter services, msc and find the apache service in the control to restart it


The second step. The first step only specifies the file name of the php extension, and does not specify the path where the extension file is located. When the extension path has been specified in extension_dir, you can omit the path and fill in only the file name, otherwise you need to fill in the complete file path. Therefore, you need to search for the text extension_dir in php.ini and find the following line of configuration.

;extension_dir = “ext"

Cancel the ; (semicolon) in this line of configuration, and change it to the file saving path of the PHP extension, as follows:

extension_dir = "e/web/php/ext"

Finally, you can write a phpinfo() function to see if There is mysqli extension


  • reply I have done all this and can connect to the database, but I still cannot use the mysqli extension. At this step, mysqli_query($link,$sql); still reports a warning Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in D:\360Downloads\Software\phpStudy\WWW\link.php on line 13, cannot be executed.
    Super木 author 2019-03-31 13:58:07
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template