php - My Zend Framework 'quoting' mess -


I have found a very simple issue for which I have a satisfactory framework manual in Zend ... or < P>

How can I put my php variable on my SQL query, there are many ways that I've lost the overview and I do not understand anything about quoting in general.

Prepared Statement

  $ sql = "Choose from where from the table ID =? And restriction =?"; $ Stmt = $ this- & gt; _db-> Query ($ sql, array ($ myId, $ myValue)); $ Result = $ stmt-> Fatch ALL ();  

I understand that with this solution I do not have to quote anything because DB handles it for me.

Zend_Db_Table and _Row Objects Inquiry on the API

$ user = new user ();

  a) $ users- & gt; FetchRow ('userID ='. $ UserID); B) $ user- & gt; FetchRow ('userID ='. $ User- & gt; getAdapter () - & gt; bid ($ userID, 'INTEGER')); C) $ users- & gt; FetchRow ('userID =?', $ UserID); D) $ users- & gt; FetchRow ('userID =', $ Users- & gt; getAdapter () - & gt; bid ($ userID, 'INTEGER'));  

question

I understand that A) is not okay because it is not quoted at all but about other versions, what's the best? C) is being treated like a statement and is automatically cited or do I need to use d) when I use it? Identifier?

Disclaimer: This information is valid according to the date of original posting. The ZF often changes, this information may be outdated with future releases, however, for archival purposes it will remain unchanged

if you type fetchRow () Zend_Db_Table_Abstract If you pass a string for a sub-class method of (which you are doing), then it will be treated as a where A Zend_Db_Table_Select part of the example.

In other words, internal, Zend_Db_Table does this:

  if ($ (where $ (for example Zend_Db_Table_Select)) select $ $ = $ This- & gt; Choose (); If ($ where! == zero) {$ this-> _where (select $, $ where); }  

Then ...:

  a) $ users- & gt; FetchRow ('userID ='. $ UserID);  

Not cited at all.

  b) $ user- & amp;; FetchRow ('userID =' .Users- & gt; getAdapter () - & gt; bid ($ userID, 'INTEGER'));  

Manually quoted as an integer.

  c) $ users- & gt; FetchRow ('userID =?', $ UserID);  

Automatically Zend_Db_Adapter _ * :: quoteInto ()

  D) $ users- & gt; FetchRow ('userID =', $ Users- & gt; getAdapter () - & gt; bid ($ userID, 'INTEGER'));  

Really, you are quoted once per time, and once via automated quote.

As far as "best" is concerned, I suggest alternative. Framework will automatically call the quoteInto parameterized value.

Keep in mind: You can always get an example of Zend_Db_Table_Select or Zend_Db_Select to fetchRow () < / Code> instead of method ...

Again, in the sub-category of Zend_Db_Table_Abstract , look like this:

  $ This- & gt; FetchRow ($ this-> Select () -> where ('userID =?', $ UserID)); Plus, it is more that you can create more complex queries, because you have too much control, only the  WHERE  section of the SQL Query Principle In, you can easily: 

 select  $ = $ this-> () -> Where ('userID =?', $ UserID) - & gt; Join (array ('Set' => 'Super ExtremeTable'), Array ('sat.user_id = userID', array ('super est column')); $ this-> Fillover ($ selection);  

Note: If given an example of Zend_Db_Select , then fetchRow () method is absolutely < Code> fetchAll () < 1

HTML>

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -