Thomas Hutton Thomas Hutton - 6 months ago 50
SQL Question

Unknown Database on Mysqli Connect... However it Does Exist

I'm getting an error 1049 on my Mysql connect file, however I have verified this table exists. And when I attempt to connect to it via PDO it works perfectly fine. So obviously there's an error in my code I'm missing.

My code:

<?php

$db = new mysqli('localhost', 'root', '', 'mysqliphp');

if ($db->connect_errno) {
die('Houston, we have a problem!');
} else {
Echo 'Everything is fine.';
}

?>


The error:

Warning: mysqli::__construct(): (HY000/1049): Unknown database 'mysqliphp' in C:\xampp2\htdocs\mysqliconnect.php on line 3
Houston, we have a problem!


What is the issue? Thanks in advance!

Answer

In your question you have mentioned table does exists that is mysqliphp but here you are passing that name as a database. hence the error