Apologies if this seems very simple. I'm just starting with PHP and MySQL and i've been stuck with this for the last 2 days.
Essentially, I am writing a user reg/login system and i'm having problems (apparently) selecting the database that user credentials will be stored in.
My code stripped down to the essentials.
<?php
$servername = "localhost";
$username = "qtesting";
$password = "test";
$database = "qtesting";
$mysqli = mysqli_connect($servername, $username, $password) or die('Error connecting to MySQL server.');;
if($mysqli->connect_errno > 0){
die('Unable to connect to database [' . $mysqli->connect_error . ']');
}
$result=mysqli_query("USE qtesting");
echo $result;
If I allowed my full code to run, it returns with "No database selected" when I attempted to run any further queries. So I pared the code back line-by-line to what you see above and turned on query logging to see what is going on.
According to my query log, a connection is successfully opened to the server but the USE query does not appear to be running. To clarify, I created the $result variable and asked PHP to echo $result for debugging purposes.
Also, you may notice I have defined a $database variable. I also attempted to select the database while establishing a connection by mysqli_connect($servername, $username, $password, $database)
Does anyone have any ideas?