database query's from class object with php -


My question is:

Do I still query this from within an object Can I:

$ result = mysql_query ($ q, $ dbc) or trigger_error ("query: $ q \ n
MySQL fut:". Mysql_error ($ Dbc)); $ dbc

or Create a singleton class for the database connection , but I think people are writing about it looking away quite negatively.

I am new to creating an object, so I do not know if I want to completely separate it with DB.

Thanks, Richard

If you are looking for a database inspection Why not consider using the DB sections provided by the Zend Framework.

These include a way to set the adapter, by default, it creates a snap to operate.

Add to the fact that by default, Zend_Db adds security and peace of mind to use parameterized queries instead of those who are basically quoted.

P> Global use is a very bad idea, by mistake it is very easy to overwrite one! Together with all other reasons you will find them to not be used with a quick Google.

Creating a DB connection with Z Framework is a picture,

  $ db = Zend_Db :: factory ('Pdo_Mysql', array ('host' = & gt; '127.0.0.1', 'Username' = & gt; WebUser ',' Password '= & gt;' xxxxxxxx ',' dbname '= & gt; "Test"  

));

It's actually as easy as that. Then you can either give quick access to individual tables to your table squares, or use the selection and statement object for more advanced queries.

In addition to this, with the Zend Framework, you can use the entire stack, if you wish, just use DB components.

If you do not want to use the Zend Framework for this, then I strongly recommend that you consider options like ORM like the theory itself DB ABSTRACT you end up with a monster very quickly , And an ORM or Zend Framework is a great many squashing squashing developers, and even there any reporting.


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 -