I’m in Chapter 4 (page 121, 4th edition). I am trying to connect to my database for the first time through my webbrowser/php.
I receive the following error when I try to connect my page with my jokes database:
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
I have tried manually creating the code and also copying the provided code from the text book. Any advice at all regarding this matter would be great!
I had the same problem in Windows 7. The error message began “Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)”
I only found the solution by reading various snippets of advice in different places. Here is the way to fix this problem, all in one place:
First, close all open programs. I stopped the Apache service and the mysql service using Windows Task Manager (click on the services tab and then on the services button in the lower right corner. Find the services in the list and select and stop each in turn.)
Next, run Notepad as administrator. To do that, find Notepad in the Windows Start menu, right click the icon and select Run as Administrator. Now, navigate to C:\Windows\System32\drivers\etc and find and open the hosts file.
Find the line that looks like this:
127.0.0.1 localhost
Uncomment that line by removing the # from the line and then save the hosts file. Close Notepad and then restart Windows.
This worked for me. Good luck. Thanks to Patrício dos Santos in the mysql forums for most of this.
Hi guys I’m having the same problem as Alex unfortunately I am a real beginner so not sure what your talking about in your replies I am assuming that for the mysqli_connect you need to change the code on the index.php file within the connect folder tried that and it didn’t work I changed the password to the password i created in mysqladmin still getting error message any ideas please would be gratefully received.
Hi Space Phoenix, thanks for the quick response I’m not sure how I’m supposed to run that php script I assumed you put it into an html page and got nothing back, when I check my apache server is says its running and it shows on the bottom Apache/2.2.13(win32) PHP/5.3.0 realise that perhaps someone so thick shouldn’t be trying to write database driven websites but I love a challenge. once again thanks for the help any ideas on where to go from here (please don’t suggest Siberia! I hate the cold.)
Hi SpacePhoenix
thanks again for the prompt reply didn’t spot my obvious mistake changed the page to php and I get a page that shows PHP Version 5.3.0 with a big list of what is enabled etc then below that configuration with apache2handler followed by lots of other bits and pieces. once again thanks for the reply
I’m having the same issue as the other challenged folks here. I have followed the suggestion from SpacePhoenix and there was no change needed (that part was configured correctly during setup).
I’m on a Windows Vista 64 bit machine and I have setup up MySql, Apache, and Windows according to the book referenced.
I’ve output phpinfo() and everything is as current as possible.
Is there something else to look at or is there a particular syntax for the following:
$link = mysqli_connect(‘localhost’, ‘root’, ‘password’);
The above leads me to believe that all I need to do is enter my password.
Fortunately I am running a mac as well as windows machine and managed to get MAMP up and running which made the whole process a lot simpler, I found a good PHP text editor which is free for windows and mac called komodo it highlights the code for you and if you get wamp up and running you can use it to follow the course. Hope this.
yep it is, I just did a reboot and now I have a different error:
“Warning: mysqli_connect() [function.mysqli-connect]: (/838860800): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Unable to connect to the database server.”
which I am guessing just means my password is wrong, had trouble with that cmd in the book too… hmm
final edit: yep, ‘Database connection established.’
reboot and a change of the pw in my code did it. thanks!
I had the same issue as above, 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.
I updated PHP as suggested and it seemed to solve the problem one time. I now get a 500 error on the web page. It doesn’t happen instantly it seems to take a minute or so. I know that the localhost, user name, and password are correct.
Error: The website cannot display the page
HTTP 500
Most likely causes:
•The website is under maintenance.
•The website has a programming error.
What you can try:
Refresh the page.
Go back to the previous page.
More information
I am on a Windows 7 box, using Apache 2.2, PHP Version 5.3.2, MySQL 5.1.
I used php-5.3.2-Win32-VC6-x86 for Apache.
I just got:
Warning: mysqli_connect() [function.mysqli-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost: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): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
I had to use 127.0.0.1 before too. Then I changed something in a configuration file somewhere (sorry, I don’t remember what I did now) so that “localhost” would “map” to the 127.0.0.1 IP
Aaarrrggghhh!!! Installation is NOT my favorite thing.