I am trying to execute an SQL query in PHP but even though the DB has been connected it returns 0 rows, but when I try to execute the same query in MSSQL it returns a row.
I have tried the one below but it returns just Boolean false:
$selecteddb = $dbi->query('select database()');
var_dump($selecteddb);
Here is how I execute my query:
$user_sql = "SELECT * from users where username='myusername' AND password='pass123'";
$user_res = $dbi->prepare($user_sql);
$user_res->execute();
$user_data = $user_res->fetchAll();
$user_unum = count($user_data);
I just want to verify that I am actually connected to the right db.
Update:
I will need an equivalent of mysql_db_name
to print the db name. This one is deprecated and does not work in php 7.
CodePudding user response:
Try 'Select db_name()' instead of 'select database()'