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 "
";
}

Difference between echo and print in php

echo and print are both language construct in php, however print returns 1 but it is not a function.

Below mentioned usage of echo and print, both are valid

echo "Hello World"
print "Hello World"

echo("Hello World")
print("Hello World")

echo can output more than 1 string while print cannot(using comma separator)

echo "Hello", "world","I am Swapnesh";
print "Hello";
print "World";

How to send email to multiple recipients in magento


$postData['offemail'] = 'sendermail@gmail.com';
$templateId = 1;
$recipients = Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT);
$recipients = explode(',' , $recipients);
array_push($recipients,$postData['offemail']);
$store = Mage::app()->getStore();
$translate = Mage::getSingleton('core/translate');
Mage::getModel('core/email_template')
->sendTransactional($templateId,
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
array_values($recipients),
'Recipient Name',
array('data' => $postObject),
$store->getId()
);
$translate->setTranslateInline(true);

System.out.print in php

System.out.print is totally valid in php likewise in JAVA. I ran this sample code and its working all fine in PHP 5.3.

$result = 5;
System.out.print(“This is a valid System.out.print with uppercase S”);
System.out.print(“<br>”);
system.out.print(“This is a valid system.out.print with lowercase s”);
System.out.print(“<br>”);
System.out.print($result);