Print Page | Close Window

Why isn't opendb.asp included in inc_theme_common?

Printed From: ProductCart E-Commerce Solutions
Category: ProductCart
Forum Name: Customizing ProductCart
Forum Description: Exchange messages with other users that are customizing ProductCart.
URL: https://forum.productcart.com/forum_posts.asp?TID=6113
Printed Date: 27-April-2024 at 6:03am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Why isn't opendb.asp included in inc_theme_common?
Posted By: Brett
Subject: Why isn't opendb.asp included in inc_theme_common?
Date Posted: 11-June-2017 at 7:44pm
I've been trying to use the JSON parser and pcf_OpenUTF8 within my theme, but I couldn't get it to work. Eventually I found out that the issue was related to ErrorHandler.asp not being included.

I ended up having to include opendb.asp to the list of includes in include_theme_common.asp, and include ErrorHandler.asp in that same list of includes.

Now it appears to be working, and pcf_OpenUTF8 is opening the file and I am able to parse it with JSON.

Is there any reason opendb.asp wasn't included in include_theme_common.asp and that instead a different copy of the openDB function was hardcoded at the bottom of inc_theme_common.asp?

Ideally I'd like to leave these changes as is, with opendb.asp and errorhandler.asp being included with inc_theme_common.asp, but if this is some kind of security risk or other issue then I suppose I'll need to find a workaround.



Replies:
Posted By: Matt
Date Posted: 11-June-2017 at 9:54pm
Including "opendb.asp" worked because it automatically opens a database connection, but that's the reason it's not included.  You want to be able to control when a database connection is open, and in most cases you don't want to open one within the header or footer.  Think about the data you need and try to save it as a static asset, or at the least cache it.  Try not to include anything dynamic in your head and footer that is going to use resources unnecessarily. However, if you have a good reason to connect to the database, contact a remote service, and parse JSON on each page load.  You should remove opendb.asp and just call the open function.

e.g. 

' Open db
call openDB()

' do something...

' Close db
call closeDB()

If you are including "opendb.asp" and not closing the connection, then you have a leak.


Posted By: Brett
Date Posted: 13-June-2017 at 7:26am
Thanks for the explanation Matt. I'm trying to use webpack to setup an asset pipeline, and typically I'd read the assets from an assets.json file. I took your advice and reverted the changes to inc_theme_common.asp. I'll have to figure out some other way to parse the assets file.

I definitely don't want to continuously connect to the DB and stuff. It already seems like this is happening too much between the regular execution, and then theme.asp, header.asp, and footer.asp (which all seem to include inc_theme_common.asp since they all run in their own context due to being included via server.execute.

I'll let you know what I end up going with.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net