0

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?

6
  • Do you have a MySQL server running on where the PHP code is running? Commented May 28, 2015 at 14:02
  • try $db_password = ""; Commented May 28, 2015 at 14:02
  • 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'. Commented May 28, 2015 at 14:02
  • @rink.attendant.6 I have a WAMP Server running on my computer. Commented May 28, 2015 at 14:03
  • @NiekvanderSteen I have changes the password in the my.ini file Commented May 28, 2015 at 14:04

2 Answers 2

2

Try this...

    $db_host = "127.0.0.1";
    $db_username = "root";
    $db_password = "";
    $db_name = "test";
Sign up to request clarification or add additional context in comments.

2 Comments

I have changed the password in the my.ini file. The problem is the $db_username is not right I think. Because I've put root there
Make sure to restart MySQL on your server.
-1

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

1 Comment

I have changes the password in the my.ini file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.