0

I already have created my database, and already have the pages in PHP ready to be connected to the database. My code of connection is the follow :

<?php
    $host = "localhost";
    $db   = "clients";
    $user = "root";
    $pass = "";

    $con = mysqli_connect($host,$user,$pass,$db) or die('Could not connect to MySQL: ' .mysqli_connect_error());
?>

When I try to execute the page with WAMP, it returns me the message :

Warning: mysqli_connect(): (HY000/1049): Unknown database 'clients'

Even the database being already created and the queries executed, it still gives me this error, as if the database was with the wrong name in the PHP or something.

Maybe is the error from not having some password from the user root or using localhost ? How can I fix this ?

Monteiro
  • 217
  • 5
  • 15
  • 3
    User access and permissions. Make sure to assign the user to the database, I've seen this error happen in that case. It's stupid error, that's why I remember it. – ArtisticPhoenix Nov 27 '17 at 20:54
  • I tried to create a new user in MySQL and give all the permisions, but I can't create, because it says that it has error of syntax while creating. And I already saw some people using localhost and root to test the database and working, but with me, it's not. – Monteiro Nov 27 '17 at 20:56
  • 1
    You have `PhpMyAdmin`? you can click "home ( house icon on the upper left ). Then in the top nav bar click "Users". If you're using C-Panel may have to do it there, because they HiJack it. Or you can just use SQL, you might have to delete the user and start over. I seen MySql like create 2 with same name before ( seemed like 2 ) and total messed the permission all up, muah – ArtisticPhoenix Nov 27 '17 at 20:58
  • I am not at the moment using PhpMyAdmin, only using WAMP. But I could try to use and see if it would help me. – Monteiro Nov 27 '17 at 20:59
  • how root user cna have permission problems? did you tried to connect DB manually? a.k.a cli -> `mysql -u root clients` also, `clients ` it's the name of the DB or of table? – Michael Nov 27 '17 at 21:13
  • Is it only for this database? If so you need to check with spelling,space, first letter capital of db name. If it's with all of your databases then it may be problem with assigning user to the database.. – Shridhar Nov 27 '17 at 21:14
  • @Michael I don't know how to go to the mysql shell through Windows. – Monteiro Nov 27 '17 at 21:16
  • @shridhar It's only for this database, and there is no spelling mistakes. – Monteiro Nov 27 '17 at 21:16
  • `win key+R` -> `cmd` – Michael Nov 27 '17 at 21:18
  • It doesn't work, it just says that the command mysql it's not recognized. – Monteiro Nov 27 '17 at 21:19
  • Are you sure you have mysql installed? try: `mysql --version`. oh you are using WAMP so maybe `mysql` exe are not in `PATH` – Michael Nov 27 '17 at 21:23
  • Yeah, I looked up here and I don't have it installed, so going to try again the command that you said at the being after installing. – Monteiro Nov 27 '17 at 21:27
  • if you are using WAMP it should include MySQL – Michael Nov 27 '17 at 21:29
  • Yeah I found here the MySQL shell line command, but it says to enter an password, and I don't know the password. This just keeps getting worst. – Monteiro Nov 27 '17 at 21:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159937/discussion-between-michael-and-monteiro). – Michael Nov 27 '17 at 21:32

1 Answers1

0

I came across this error sometime ago while using MySQL database with node.js, I just deleted the database and created it again. It's funny though, but that was how I solved the error. Try creating the database again with another database name.

Efam
  • 23
  • 3