When use of back ticks in table name solves my problem in PHP/mysql

While playing with the code today, I found an interesting benefit of using back ticks in the table name in mysql query.

I created a table in my database as “abc.test” and added some dummy data to the table as shown in below screenshot.

table with a dot

Now with a simple mysql_query I was trying to fetch the data but its returning nothing, after a check I found that i missed those back ticks from my table name.

Incorrect Query (without back ticks)

mysql_query(“SELECT * FROM abc.test”);

Correct Query (with back ticks)

mysql_query(“SELECT * FROM `abc.test`”);

My whole working php code, to fetch data –

$conn = mysql_connect('localhost','root','');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db('stcktest', $conn);

$result = mysql_query("SELECT * FROM `abc.test`");

//print_r(mysql_fetch_assoc($result));

while ($row = mysql_fetch_assoc($result) )
{
echo "Id is : ".$row['id']." "." Name is : ".$row['name'];
echo "
";
}