0

I'm start my own study on php using wamp but when I try to establish a connection between my database and php code I always receive this message. I tried some diferent courses and for all of then I recieve this error. I tried to reinstall wamp server, verify some privilegies, the phpmyadmin create tables, insert into database normally but the code doesn't connect to the database.

Below is my connection code:

<?php
    $servername = "localhost"; //default by wamp, I don't change the port, still using 80.
    $database = 'curso_estoque'; //created on phpmyadmin
    $username = "root";
    $password = "";
    $conexao = mysqli_connect($servername,$username,$password,$database);
 ?>
FanoFN
  • 6,815
  • 2
  • 13
  • 33
Walters Souto
  • 21
  • 1
  • 1
  • You must be giving an incorrect database name in the arguments to `mysqli_connect()`. Check the name carefully. – Barmar Jan 17 '20 at 00:46
  • Where your code? – Calos Jan 17 '20 at 01:16
  • I checked the name, but this error happened in other tutorial that I tried, first of all I thoght that was something that I forgot or misstep but when I change the tutorial I kept receving the same error; The code above is the one who I'm using, my database is "curso_estoque" (created on phpmyadmin on mysql) – Walters Souto Jan 17 '20 at 14:58

1 Answers1

0

Make sure you have created a database and you are in the same one, query like

CREATE DATABASE mydatabasename;
USE mydatabasename; 

Refer :- ERROR 1049 (42000): Unknown database 'mydatabasename'

Ananth Sathvick
  • 144
  • 1
  • 11
  • "Unknown database" comes from the server, it must already be running. – Barmar Jan 17 '20 at 00:45
  • You're missing the database argument to `new mysqli()`. – Barmar Jan 17 '20 at 00:46
  • I typed the command USE with my databasename but doesn't work; Yes, the server is running, I can use normally mysql commands on phpmyadmin; I serchead on php documentation and tried use the argument new mysqli() but the error still the same. – Walters Souto Jan 17 '20 at 13:35