0
votes

I've installed a WAMP server. Now I want to connect to a MySQL database using php. I have one problem you need to get the username. This is the code I use. Its from php.net http://php.net/manual/en/mysqli.quickstart.connections.php

<?php
$db_host = "localhost";
$db_username = "root";
$db_password = "password";
$db_name = "test";

$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";
?>

I get the following error:

Warning: mysqli::mysqli(): in C:\wamp\www\Atletieker\dbconnect.php on line 7 Failed to connect to MySQL: (1045) Accès refusé pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI)

Warning: main(): Couldn't fetch mysqli in C:\wamp\www\Atletieker\dbconnect.php on line 11

How do I get the username of my database?

2
Do you have a MySQL server running on where the PHP code is running?rink.attendant.6
try $db_password = "";viral
Using WAMP, your hostname should be 'localhost'. (you are connecting to your own machine). This is the case, since you are not getting any connection errors. This error is telling you that you are entering a wrong password. EDIT: I believe the default WAMP MySQL password is 'root', and not 'password'.Niek van der Steen
@rink.attendant.6 I have a WAMP Server running on my computer.Roy Berris
@NiekvanderSteen I have changes the password in the my.ini fileRoy Berris

2 Answers

2
votes

Try this...

    $db_host = "127.0.0.1";
    $db_username = "root";
    $db_password = "";
    $db_name = "test";
-1
votes

Obviously the $db_password should be empty, if you haven't changed any settings the default password should be blank.