I cannot connect a database created with phpmysql

Reading PHP & MYSQL from Kevin Yank, 4th edition;

I put those two files in the directory “connexion” under www as said in the book :

index.php :



<?php
$lien = mysqli_connect('localhost','root','');
if(!$lien)
{
$resultat='impossible_de_se_connecter_au_serveur_Mysql';
include 'resultat.html.php';
exit();
}
if(!mysqli_set_charset($lien, 'utf8'))
{
$resultat = "impossible de cofigurer l'encdage de la connexion &agrave;la base.";//message = no success
include 'resultat.html.php';
exit();
}
if(!mysqli_select_db($lien, "ouvrage"))
{
$resultat = 'la base de donn&eacute;es des blagues  est introuvable';
include 'resultat.html.php';.";//message = no success
exit();
}
$resultat = 'connexion &agrave;la base r&eacute;ussie.';.";//message = no connected database
include 'resultat.html.php';
?>

and

resultat.html.php :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>resultat de PHP</title>
<meta http-equiv="Content-Type" content="text/html: charset=utf-8" />
</head>
<body>
<p>
<?php echo $resultat ?>;
</p>
</body>
</html>

and I get the last error message : no connected database
that exemple is in the 4 th chapter of the 4 th edition de PHP & MYSQL about Kevin Yank

Would you give me a reason why ?

Thank you very much,

Philippe

Have you got MySQL installed on your set-up?

You aren’t passing a password, is this correct?

Try:

$lien = mysqli_connect('localhost','root','root');

Y have all install with wampserver and Y have leave my password as “”.
I will try what you say but, I am at work (Y have not a computering job Y just may sending mail), all what Y try for my learning PHP and MySql is at home so I will wait that evening, (at home),
waiting,
thanks so much for your help and I shall naturally keep you informed of any result about your suggestion when I recover my computer at ome that evening.

P.S. : Y try the same with “Java and OBCD” and Y do a query with success, with the same database, the same wampserver, and Y think that my PHP code is Ok, so Y think it’s strange

Philippe

Thank you

Hi Philipe, quick note on your English, you need to be writing ‘I’ not ‘Y’:

I have all install with wampserver and I have leave my password as” :slight_smile: