By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,160 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

error creating database in mysql

P: 1
Hi i got this error help

Error:

Error creating database: Access denied for user ''@'localhost' to database 'mydb'

The code is:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <?php
  4. $servername = "localhost";
  5. $username = "username";
  6. $password = "";
  7.  
  8. // Create connection
  9. $conn = mysqli_connect($servername, $username, $password);
  10. // Check connection
  11. if (!$conn) {
  12.     die("Connection failed: " . mysqli_connect_error());
  13. }
  14.  
  15. // Create database
  16. $sql = "CREATE DATABASE myDB";
  17. if (mysqli_query($conn, $sql)) {
  18.     echo "Database created successfully";
  19. } else {
  20.     echo "Error creating database: " . mysqli_error($conn);
  21. }
  22.  
  23. mysqli_close($conn);
  24. ?> 
  25. </body>
  26. </html>
Apr 2 '15 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,031
You did not copy your code AS IS...

above code should lead to this error:
Connection failed: Access denied for user 'username'@'localhost' (using password: NO)

Because you try to logon as user 'username'
Apr 4 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.