Database driven websites page chapter4

hi everyone i am new to db websites and theses forums i have brought the book by kevin yank database driven websites and i have got to chapter 4 and followed it word by word but i am haveing a problem with the database error:

Warning: mysqli_connect() [function.mysqli-connect]: (/838860800):

what is happening it should say

unable to connect to the database server.

this is when i changed the password to test see if it is working when i use the correct password it says connected to database but when it says chage password to see if it gives the unable to connect to the database server. i get this error above i have unistalled it and reinstalled the software but all that happens is it changes the number in the error this is the code from the book and i cant work this error out can anyone help me asap thanks.

the code:

<?
$link = mysqli_connect(‘localhost’, ‘root’, ‘bail’);
if (!$link)
{
$output = ‘unable to connect to the database server.’;
include ‘output.html.php’;
exit();
}
if (!mysqli_set_charset ($link, ‘utf8’))
{
$output = ‘unable to set database connecion 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’;
?>

and the output code is :

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” <“http://www.w3.org/TR/xhtml1/DTD/xhtm
-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
<title>Untitled Document</title>
</head>
<body>
<? echo $output; ?>
</body>
</html>

when i changed the password to test see if it is working when i use the correct password it says connected to database but when it says chage password to see if it gives the unable to connect to the database server

This sounds like what’s supposed to happen.

When you use the correct password, you connect to the database.

When you use an incorrect password, you cannot connect to the database.

So why is this wrong?

instead of saying unable to connect to the database server.

it is giving this error: Warning: mysqli_connect() [function.mysqli-connect]: (/838860800):

but it should say unable to connect to the database server.

If you want to suppress error messages from a function, you can add a @ before the function name

$link = @mysqli_connect('localhost', 'root', 'bail');

On a production website, you’d change your PHP configuration to not display errors but instead log them, so you don’t need (or want) to suppress them.

thank you dan that as worked but it not in this book and i am very new to databases and php at least i can move on through the chapter now thankyou
bail

thankyou everyone who as tred to help me but i think it time to give up ive tryed everything you have said and still no good time throw book in the bin would any one know of a good book that would help me learn php and msql
thanks bail
ps. if you now any good books i can buy please would you give me the name and author

The books are about programming, they’re not going to help you with the basic issue of setting up the servers you’re having. Buying a different book won’t help because they’re just going to repeat the same information that comes from the vendors of the software (Apache, MySQL, PHP) you’re installing.

Maybe you should sidestep it entirely and just get some cheap web hosting and play there while you go through the book.

who u think u talkin to dan the book spoused to set it up its load rubbish and waste money so mind your own business if i wanted cheap webhosting iwould have proberly come to you mr market guru and been ripped off even more people like you make me sick think you know everythin, so mind it

No reason to get angry, you were just thanking me a few minutes ago, I was trying to help. I don’t want to see you get even more frustrated by buying more books that can’t help you with this problem. I don’t work for SitePoint and I don’t get anything out of you buying anyone’s book or hosting.

You might look through the book’s eratta as there are some notes on changes since the book was printed.

If all else fails, you can try uninstalling everything you installed, and downloading XAMPP. It is a program that installs Apache, MySQL and PHP for you all at once.

Bail,
I am sorry you’re having trouble with this book but I can tell you it is a very good book otherwise it is not logical to have it printed in 4 editions nor to see that it is out of stock now.

Moreover Dan is one of the most valuable and knowledgeable members here! And he’s a very nice person and tried to help you with your issue and he’s really good in what he does and believe he’s not solely a Marketing/E-commerce guru I’ve been around here for long years now and Dan helped me as he did with hundreds of members so please don’t be rude while he was trying to help you! I understand your frustration but believe me things will definitely be smoother if you calm down a bit and accept to be helped.

You will probably need to search for complementary info on the net (tutorials, forums, articles) in order to completely profit from the book.
And as Dan suggested you can download XAMPP or EasyPHP to have a fully functional PHP/MySQL developing environment.

So really there’s no reason to get upset and use this aggressive tone. :wink:
Good luck :slight_smile:

I hear you loud and clear bail.

I tried the Ruby on Rails book. It gives instructions for how to use InstantRails. I couldn’t get it working and ending up installing the components individually.

I tried the Build with PHP + MySQL book. It gives instructions for how to install the components individually. I couldn’t get things working and ended up using XAMPP (I tried WAMP and EasyPHP too but without luck).

I’m now trying Build with ASP.NET which gives instructions for how to install Visual Web Developer. My old OS won’t support it so I installed Visual Studio instead. My OS won’t support IIS so I intalled PWS.

So why do these books give installation instructions that don’t work?!?

My guess is that they do work for a majority of people. just that I never seem to be in that majority.

Over-simplified, but the key things to consider are:
your Operating System (it limits what will be supported)
your server
your language engine
your database engine

If you can’t get those installed and working happily together by following a book’s instructions, don’t keep banging your head into the same wall. Try alternative approaches.

Although you may run into some problems by using a different platform than what the book is using, I think as long as you’re close things should be OK. Because this book is primarily concerned with PHP and MySQL as long as you have the same versions (or newer) of PHP and MySQL on your localhost I don’t think youll have any problems. Even if you have to use older versions, you shouldn’t be completely crippled to the point where you can’t learn most of it.

i have sorted it but i am gettin this error now
Parse error: syntax error, unexpected ‘)’ in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2
everthing is in the database exactly how it says in book the code is exactly same as book here is the code
<?
$link = mysqli_connect (‘localhost’,‘root’,‘bailuk’,);
if (!$link)
{
$output = ‘UNABLE TO CONNECT TO DATABASE SERVER.’;
include ‘outp.html.php’;
exit();
}
if (!mysqli_set_charset($link, ‘utf8’))
{
$output = ‘UNABLE TO SET DATABASE CONNECTION ENCODING.’;
include ‘output.htmp.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’;
?>
any ideas

and dan i read it as you was sayin i was thick
qoute;
Maybe you should sidestep it entirely and just get some cheap web hosting and play there while you go through the book.
i already have host im just learning php mysql
any way forget it i was in mood and then read that like so :
thanks to everyone who as tryed to help and i appoligse to anyone who taken it the wrong way
thanks bail

No problem. I wasn’t trying to say that. The error is because on this line:

$link = mysqli_connect (‘localhost’,‘root’,‘bailuk’,);

You have an extra comma after your password

thankyou for your reply when i reamove it i am still getting the same error

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

this is the code:
$link = mysqli_connect (‘localhost’,‘root’,‘bailuk’);

i have also tryed the @ like you said before but all i get is a blank white page

thanks again bail

In your php.ini file there should be a line:

extension=php_mysqli.dll

does that line have a ; at the start of it, if it does, remove the ; then restart the server.

yea it does have that kind of code and no it as not got the ; at the beginning

there is also the extension=php_mysql.dll which i have removed the : and then replaced it and it still
makes no diffrence still get the error

thanks bail

I don’t know what you finally ended up installing, but you may have more than one php.ini file. eg. in my XAMPP folder I have one in
…/apache/bin/
and another in
…/php/

ok thankyou for your help i only have one php,ini file in php so it looks like remove all and reinstall again haa keep tryin dont give up ill get there one day back in bit gonna reinstall everything
thankss bail

i have unistalled all the programs and removed the mysql files and apaches folder out of
program files and restared my comp when i reinstall the programs everthing is still there from the last install were eles does it put the files so i can do a complete install
thanks bail
oh removed from control panel

If you uninstalled everything and removed the folders, I don’t see how the old ones would still be there. ??? Anyway, Do you have one of the following operating systems and are using the correct files for Apache, MySQL, and PHP ?

Windows XP, Windows Vista, Windows 7

MySQL
	Windows Essentials (AMD64/Intel EMm64T)
	Windows Essentials (x86)
PHP
	5.2.x zip Windows Binaries
Apache
	Win32 Binary without crypto (no mod_ssl) 2.2.11-win3-x86-no ssl.msi

Mac OS X 10.5 (Leopard)

MySQL
	Mac OS X 10.5 (x86_64)
	Mac OS X 10.5 (x86)
PHP 5	- built in
Apache 2.2	- built in

Ubuntu 8.10 (Linux)
also Fedora, Debian, openSUSE, Gentoo

MySQL	- non RPM
	Linux (AMD64/Intel EM64T)
	Linux (x86)
Apache
	Unix Source: httpd-2.2.11.tar.gz
PHP
	php-#.#.##.tar.(gz|bz2)

And if you’re trying to install PHP 5.3 you’re using the correct one as described in the books errata ? http://www.sitepoint.com/books/phpmysql4/errata.php

p.12 Installing PHP

Although this book provides download and installation instructions for PHP 5.2, the newly-released (at the time of this writing) PHP 5.3 includes some new download options that aren’t covered in the book.

There are four different versions of PHP 5.3. for Windows: VC6 Non Thread Safe, VC6 Thread Safe, VC9 Non Thread Safe, and VC9 Thread Safe. Talk about confusing!

First of all, you definitely want a Thread Safe version of PHP. The Non Thread Safe versions are not suitable for use as a plugin for Apache.

Secondly, assuming you will install (or have already installed) a version of the Apache HTTP Server from httpd.apache.org (see page 13), you will need the VC6 version of PHP.

In short, to follow the instructions in this book, you need the VC6 Thread Safe version of PHP 5.3 for Windows.