Chapter 4 - Cannot connect to MySQL data through php script

Chapter 4 of Kevin Yanks book page 117

I cannot connect to my MySQL server with the mysqli_connect function at all. I have read plenty of forums tips but none of them work.

It would help if anyone, especially anybody from Sitepoint or the author of this book could help with this issue.

My MySQL Server works fine. I’m just having problems connecting with the php script.

Please help. I would like to continue on with the book and put a site together eventually.

I appreciate it.

NS10

I just tried the link and it worked. This linked also helped:

http://dev.mysql.com/doc/refman/5.1/en/apis-php-mysqli.setup.html

Thanks!

NS10

I read the manual in the link provided. I added the correct path in the Environment Variables section. I restarted and tried to connect, but I still got the same error. I am at my wits end with this. I do not want to reinstall everything, I would rather work through it as it is good for troubleshooting experience. Any help is greatly appreciated.

Take a look at the section “Installing on windows systems”, on this page of the PHP manual.
More specifically, look at what it says about libmysql.dll
That may be the problem.

Still nothing guys. Nothing that was recommended on this post works.

Is there maybe a upgrade to either Apache, PHP, or MySQL that I need to install to remedy this problem? Maybe reinstalling one on these technologies.

NS10

try


$conn = mysqli_connect('localhost', 'root', 'password') or die ('ERROR '.mysqli_errno().': '.mysqli_error());

What error do you see?

I’ve check to see if mysqli is enable and it is and it still does not work.

What can I try next to get this thing working?

MySQLi is not enabled.
Did you restart your webserver after changing the configuration?
Did you get any error messages during the restart?

<?php
$link = mysqli_connect(‘localhost’, ‘root’, ‘password’);
if (!$link)
{
$output = ‘Unable to connect to the database server.’;
include ‘output.html.php’;
exit();
}

I replace the word “password” with my password for my MySQL database. Still, it does not work

In your php.ini file is mysqli enabled? If it is disabled you’ll see a line like below:

;extension=php_mysqli.dll

If it’s disabled, to enable it, remove the ; and save the php.ini file then reboot the server.

My server does not have mysqli enabled, just mysql and PDO. Are you sure yours does?

plz paste to us your code to connect with mysql

Here’s the error message I get

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

Anything else I could try?

NS10