I know there’s another thread on this but it doesn’t help me.
Reading Database Driven Websites and I come to this error when I try to run this code:
<?php
$link = mysqli_connect('localhost', 'root', 'password');
if (!$link)
{
$output = 'Unable to connect to the datbase server.';
include 'output.html.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';
include 'output.html.php';
exit();
}
if (!mysqli_select_db($link, 'ijdb'))
{
$output = 'Unable to locate the joke database.';
include 'output.html.php';
exit();
}
$output = 'Database connection established.';
include 'output.html.php';?>
Of course, I filled in password with my real password. I checked my PHP info and the Loaded Configuration File was configured correctly i.e. extension=php_mysqli.dll was uncommented in php.ini. My php version is 5.3.5. I installed the thread safe version of PHP. I tried changing the localhost to 127.0.0.1. I tried everything in that thread and nothing helps. I can’t even get a different error message. It just keeps coming up: Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2.
Can someone please help. I’m itching to move on in the book. Thanks in advance.
Ok. I figured out the original problem but now I get these error messages:
Warning: mysqli_connect() [function.mysqli-connect]: [2002] No connection could be made because the target machine actively (trying to connect via tcp://127.0.0.1:3306) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): No connection could be made because the target machine actively refused it. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Fatal error: Call to undefined function mysqli_connect()
then, the “mysqli” module is probably not being loaded by php. You can confirm this by running phpinfo(); in your php code. If “mysqli” is not listed in the resulting page, then it is not being loaded.
I’m using php 5.3.6, and mysql 14.14 on Windows 7. The solution that successfully loads “mysqli” for me (and prevents the above error message) is to download “libmysql.dll” from libmysql.dll free download - DLL-files.com and put it in my path, or just copy it to my Windows folder.
Ironically, I found this solution by reading PHP: Installation - Manual, which says that for php 5.3.0+ you don’t need to configure access to “libmysql.dll”!