Jump to content

SQL in header.tpl


Recommended Posts

What is the safest way to do SQL queries on my own Presta Shop database on header.tpl? Currently I have been doing:

{php}
$username = 'username';
$password = 'pass';

mysql_connect("localhost", $username, $password) or die(mysql_error());
mysql_select_db("shop") or die(mysql_error());

{/php}



in my header.tpl, but I feel there is another way and more safer way, but I'm not sure how to access the database from the config files.

Link to comment
Share on other sites

Generate lists of categories and such on a nav bar. I know there is a module for this, but it does not suit my needs and hence I made my own nav bar using jkmegamenu in the header.tpl and want a query to list all the categories and manufacturers.

Refer to this topic I made awhile ago:
http://www.prestashop.com/forums/viewthread/66076/general_discussion/solvedadding_categories_and_manufacturers_to_a_drop_down

Link to comment
Share on other sites

You really should do that in header.php and return only smarty variables to be used in the template.
Also, use the PS style stuff.

the Db class has already been created when header.php is called so you can run your sql like this:

$result = Db::ExecuteS('sql query here');



Take a look at the PS code to see how it is done.

I learned about doing this stuff when I wrote my own class to generate our dynamic reports and called a function in this class from
the OrderHistory class after payment was validated.

Link to comment
Share on other sites

×
×
  • Create New...