Building queries with Zend Query Builder

Learings, PDO, Technology, Zend, Zend Select

I have often seen people not using the full potential of zend query builder. Often I have seen people writing query like:

$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$statement = $db->prepare("SELECT * FROM users");


$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$statement = $adapter->prepare("SELECT email FROM users WHERE password = :password");
$statement->bindValue(':password', self::PASSWORD);

Although there is nothing wrong with the above approaches but a better way can be:

$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$columns = array('email');
$select = $db->select()->from('users', $columns)->where('password = '. $db->quote(self::PASSWORD));

This gives a better readability, better maintainability and any modifications in coluns and conditions can easily be done.

I will come up with wriring more complex queries in my next post.


Difference between DELETE and TRUNCATE


I found out following differences between DELETE and TRUNCATE:

  • If we truncate the table, the indexes get reinitialized. While in DELETE they start from the last index where we left.
  • Truncate recovers space also. Delete does not recover space.
  • If there is a foreign key constrain in the table, it cannot be truncated. Instead it can be DELETED.
  • One night @ Reservation Counter

    Experiences, Tours

    Diwali is the most awaited festival in our part of the country. Many, like me, take this festival as a home going opportunity. Taking a leave from daily work and visiting your parents is just what the festival is all about(well, atleast for me).

    In spite of being active I didn’t got reservation. Disappointed, I decided that I will go for Tatkal reservation. Since it is avaliable only a day before so i had to wait.

    The day arrived. I planned to leave office early that day to go and sit in the line. I was prepared for a heavy rush. It was about 9:00 PM when i reached the PALAM(New Delhi) railway station. There is a person who writes the name of the persons in line for the reservation on FCFS basis. In spite of reaching 12 hours before the counter opening time, I had my name at 28th number and that too there were two lists. Spent the night some how.

    Next day when the counter opened, there were 50 people more behind me. Now the counter opened and there was a callous enviorment all around. All the people were mainly taking tickets for Bihar. So i thought may be there is a chance.

    My number came, I got a waiting of 38. Disgusted and disappointed, i decided not to take that ticket. Came back directly to office. Here was a surprise waiting, the next was declared off. Phew..had the reservation been done, it would have gone into vain!! 🙂 🙂

    Now will leave in another 2 hours from office. Looking forward to the trip!

    Happy Diwali.

    My God Sachin Tendulkar

    Experiences, Learings

    It was a gloomy morning of February 1992 when Sachin Tendulkar (my GOD) scored a captivating century(114 to be precise) on the fastest pitch in the world PERTH and that marked the advent of GOD himself.

    My conviction in GOD grew when he teared apart the English bowlers in 1993 at Chennai making a statement come true “British invented cricket, Tendulkar conquered it.”
    Who can forget that last over of HERO CUP where he let only 3 run slip by when only 6 were required. Ishant Sharma may be interested here .

    The subsequent years (94/95/96/97) saw the rise of GOD. May it be NZ in 94, Kangaroos in Singer cup, A Man of the series performance at Wills cup in 95 or the 96 world cup in which he was the highest run scorer. There was no one defying Sachin Ramesh Tendulkar.

    Meanwhile, I was also growing and got into school. Silently my childhood was connected with the master in every single possible way. I would smile and feel proud when he would score a century, would tend to cry when he got out early. Would indulge in arguments about him and also worship him.

    Then came the storm at sharjah which gave Mr. Warne nightmares. While it was a nightmare for Warne it was a feast for a devotee like me

    Who can forget the commitment he showed for the country, when he flew to England and scored a century right from his father’s funeral. With the start of new millennium GOD embarked 9000 runs in ODI with above 25 centuries.
    Mean while I am into my double figures of age(10 years) and still would tend to cry when he got out early. Would indulge in arguments about him and also worship him

    In 2001 GOD becomes the first to reach 10000 in ODI(praise the lord).A GODLY performance at 2003 WC where a nightmare performance by our bowlers broke the dream again.Goes to Australia in 2004 and scores a mammoth 241. Also equals Gavaskar’s record of centuries.Tennis elbow starts to creep in.
    2005, God cemented his place in immortality by breaking gavaskar’s record. Places most number of test matches for India in 2006.
    Mean While I have passed my secondary exams nd still would tend to cry when he got out early. Would indulge in arguments about him and also worship him.

    2008: Becomes the highest run getter in all ODI and tests.
    Mean While I have passed my senior secondary exams and entered engineering but would still tend to cry when he got out early. Would indulge in arguments about him and also worship him.

    2010: Quoting Ravi Shashtri: “First man to reach to a double hundred in ODI and its the super man from India”. Really Super Man?? Way above him..Actually GOD.

    DREAM COME TRUE year. 2011. We are the World Cup champs. Most importantly GOD is the WC champ. 2nd Highest run getter in tournament and Oh boy was he happy!!!Reaches 50 test hundreds(50 my god!!).

    Date: March 16 2012
    Match: Bangladesh Vs India
    Series: Asia Cup
    Venue: Sher-e-Bangla Stadium, Mirpur
    Sachin Tendulkar completes his 100th ton
    Mean While I have passed my engineering got a job and would still tend to cry when he got out early. Would indulge in arguments about him and also worship him.

    After 463 ODIs, 18,426 runs and 49 centuries, Sachin Tendulkar announces his retirement from ODI cricket on December 23, 2012.
    That day ODI cricket ended for me.

    After 198 Tests, 15,837 runs and 51 centuries, Sachin Tendulkar announces his retirement from Test cricket on October 10, 2013.
    That day Test cricket ended for me.
    Mean While I would still tend to cry when he got out early. Would indulge in arguments about him and also worship him.

    I now realise that my childhood is over. I am a responsible guy now. I wont stop to see any body batting, wont cry seeing any one getting out, wont fight for any one, wont feel butterflies in my stomach and wont feel my pulse droping when somebody gets out.

    Thank you Sachin Tendulkar for every single joyous moment you have given to me in last 22 years. I wont be the same after 18th November 2013.