php - joomla 2.5 virtuemart sql fetch db -


I'm trying to create a module for joomla 2.5. I try to get some element from DB and after that I want to resound.

I tried this in phpmyadmin

  SELECT * FROM 'uhhu_virtuemart_manufacturers' WHERE virtuemart_manufacturer_id = 7  

I take 1 record back , So now I try to do it with php:

   Choose ( '*'); $ Query-> ('Uhhu_virtuemart_manufacturers'); $ Query-> Where ('virtuemart_manufacturer_id = 7'); $ Db- & gt; SetQuery ($ query); $ Option = $ db- & gt; Load Object List (); Return $ option; If ($ db-> getErrorNum ()) {echo $ db-> GetErrorMsg (); Go out; }  

Nothing is happening, tried to do it in many ways, but I failed. Anyone have an idea?

First of all, you should avoid all values ​​and column names using the quote ( ) and quoteName () . Secondly, you should use the normal database table prefix ( #__ ), which means that if you ever change the prefix name, you will not need to update your query. Third, you are not really trying to produce any results, take a look at the following:

  $ db = JFactory :: getDbo (); $ Query = $ db- & gt; GetQuery (true); $ Query-> Select ($ db-> quoteName (array ('*')) -> ($ db-> from quoteName ('#__ virtuemart_manufacturers')) -> where ($ db-> Quotation name ('virtuemart_manufacturer_id'). '= 7'); $ db- & gt; setQuery ($ query); $ option = $ db- & gt; Load object list ($); Forex option ) {Echo $ row-> NAME_OF_COLUMN;}  

update:

To connect to other databases, you can use the following and then Query can run

  $ option = array (); // stop problem $ option ['driver'] = 'mysql'; // database driver Variant name $ option ['host'] = 'db.myhost.com'; // database host name $ option ['user'] = 'fredblog'; // user $ option for database authentication ['password'] = 'S9 (39 s pound h [% dkFd'; // password for password database authentication ['database'] = 'big database'; // database name $ option ['prefix'] = 'abc_'; / / Database prefix (can be empty) $ db = JDatabaseDriver :: getInstance ($ option); $ Query = $ db- & gt; GetQuery (right); $ Query- & gt; Select ($ Db-> quoteName (array ('*')) - & gt; ($ Db-> quoteName ('#__ virtuemart_manufacturers')) - & gt; Where ($ db-> quoteName ('virtuemart_manufacturer_id') '= 7'); $ Db- & gt; Setting ($ query); $ Option = $ db- & gt; Load Object List (); Forex Currency ($ option as $ line) {echo $ row-> NAME_OF_COLUMN;}  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -