Database driven websites chapter 4

HELLO
my name is bail im new to this forum i have got to chapter four of the book and im getting errors this is the code it says type;
<?
$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’;
?>

but the problem i have is when i change the password like it say’s in book to test the password is working im getting error like this

Warning: mysqli_connect() [function.mysqli-connect]: (/838860800): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

could anyone give me any advise i have tryed reinstall of all the software a few times and all that happens is the number in the error keeps changing
thanks

change your link directive to

$link = mysqli_connect('localhost', 'root', 'bail') or die(mysql_error());

and it will give you a much better description from the mysql server as to why things aint working.

All pointers suggest that the password is not right. are you sure you have updated your server copy of the script with the new password?

thankyou for your reply yes neil i think its sorted i put a @ infront of $link = @mysqli_connect(‘localhost’, ‘root’, ‘bail’);it is working but this is not stated in the book at least i can got to the next chapter now thankyou i also have another question on the forum that no one as asnswered if you could answer that it would be big help thankyou for your help
bail

All the @ symbol does is hide the visible message. The error would actually still occur.

Take the @ symbol out and paste the error message you’re getting.

Warning: mysqli_connect() [function.mysqli-connect]: (/838860800): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

i have unistalled and reinstalled but all that changes is the number in the error

Warning: mysqli_connect() [function.mysqli-connect]: (/838860800): in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Are you making use of the errata for the book? It’s kind of important.

For example, the correction for page 12 might be of use for you.

[indent][list][*]p.12 Installing PHP[/list]
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.[/indent]

thanks pmw i will try it and let you know
thanks bail

hi pmw i have tryed all that and still same its doin me head in i got it workin on my main comp fine just laptop wont have it back to drwing board thanks bail

In your php.ini file there are two lines to do with MySQL:

extension=php_mysql.dll
extension=php_mysqli.dll

Do either of them lines have a ; at the beginning of them?

If you’ve tried what I posted in my previous message, then that’s not enough.

You need to go through the complete errata, and ensure that you have applied all of the fixes in there.


Paul Wilkins

the extension=php_mysqli.dll does not have the ; i removed it like the book says i all so downloaded the one pmw said and installed it and now im getting this error mysqladmin: connect to server at ‘localhost’ failed
error:'access denied for user ‘root’@‘localhost’ (using password:yes)

but i know 100% the passwoed is correct
i would like to say thanks to everyone who is trying to help me sort this problem out

                                            thankyou bail

What does the book say about setting up the password?

mysqladmin -u root -p password "newpassword " i have put new password were it says then it says press enter then enter again with out the password then mysqladmin -u root-p statuse then enter passwoed
thanks bail

What do you see when you enter the following?

mysqladmin -u root -p status

i get enter password when i enter password i get the error and i have tryed it without the password and still get the error

mysqladmin: connect to server @ localhost failed
error access denied for user root@localhost (using password :no)

if use passwored get (using password :yes)

That’s good to know, because the password has not yet been changed, as the password is stored in the database.

Don’t bother with the password until you get the server up and going. You won’t be able to save the password until the database is working.

I presume that you get a similar variation of the error with this command?

mysqladmin -u root -p version

Have you confirmed that the mysql service is active?

how do i find out if its running it is in the task manager msqld.exe like it says to check in the book is there another way