Build your own Database Driven Website, Chapter 4

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.

I looked on threads started by others about this and none helped (unless I’m doing what tehy say wrong). Also, I couldn’t get chapter 3’s last example to work, where you place the welcome php and html in the welcome folder, though it cited a syntax error for the { of the first else, which doesn’t make sense to me. Not sure if that gives you any hints… (everything before that went smoothly)

Hi there,

I was experiencing the same problem and posted the solution that worked for me here:

I am very new to this - doing a volunteer website for charity border collie rescue group - so I appreciate patience with my ignorance on this!

I get this error:
Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50146 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\index.php on line 3

Here is line 3 of my code:
$link = mysqli_connect(‘localhost’, ‘root’, ‘mypwhere’);

After the error msg above- I got the ‘successful connection to database’ msg

When you first tried to access the script, was you using http://localhost ?

Is the MySQL service/server running?

I just replaced localhost with 127.0.0.1 and now get this error

Warning: mysqli_connect() [function.mysqli-connect]: [2002] A connection attempt failed because the connected party did not (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): 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

okay I replaced 127.0.0.1 with local host just for the hell of it and I got the same error except it’s “via tcp://localhost:3306” instead of 127.0.0.1

I’m pretty confused at this point

I’ve just run into the same problem:

I’m getting the following error

Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\database\index.php on line 2

I have apache and mysql running on vista - I’ve tried the solutions posted so far, changing localhost to 127.0.0.1 and adjusting the windows hosts file (and restarting my machine) but having no luck at all.

Running the latest apache and PHP Version 5.3.3

Build Your Own Database Driven Web Site Using PHP & MySQL, July 2009 4th Edition pages 106-108.

I am just a new PHP student but I am confused by the example code while reading pages 106-108…

When going to the count10/ directory, index.php brings up 1 2 3 4 5 6 7 8 9 10 on my browser, no HTML output from the count.html.php file, in the same directory.

code: count10/index.php

<?php
$output = ‘’;
for ($count = 1; $count <= 10; ++$count)
{
$output .= "$count ";
}

include ‘count.html.php’;
?>

Shouldn’t the include statement be outputting the HTML contents of the count.html.php file to my browser?

code: count10/count.html.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title>Counting to Ten</title>
<meta http-equiv=“content-type”
content=“text/html; charset=utf-8”/>
</head>
<body>
<p>
<?php echo $output; ?>
</p>
</body>
</html>

I am not getting it! I have played with a few CMS systems and Header.php and Footer.php output HTML data…why doesn’t this example? Shouldn’t I see “Counting to Ten” above the numbers 1-10?

Thanks for your help.

Jake

I tried throwing in some parenthesis and double quotations, still no change!

include (‘count.html.php’);

include (“count.html.php”);

:sick:

If you are getting a call to an undefined function, then your PHP is not recognizing your MySQL for some reason. It’s just not hooking up: that’s why you’ve an error as soon as you attempt mysqli_connect(). I don’t know why.

Have you uncommented extension=php_mysqli.dll in your php.ini file?

If you look at the browser’s view-source you should see the HTML mark-up. But the only thing you should see rendered is the number sequence. The “Counting to Ten” is in title tags - which shows in the browser’s title bar, not the page.

^ Yes I have.

Da!! Yes, so true, I wasn’t even paying attention to the HTML markup, now that I am looking at the code, there is nothing in the <body> tags but PHP code, hence the number count only!! How could I be so blind, thanks for taking the time to point this out!! I have to grow a pair of programmers eyes!