Solved

Need advice on the approach of developing a web application

Posted on 2011-03-06
1
290 Views
Last Modified: 2012-05-11
We have a DB class (Zebra database). We need access to the DB from almost every page in the php application.
Is there any performance / security issue with global DB variable?
If yes, What is the best way to reduce the load / security concerns, if any?
Also, we have OO just for the DB. Rest all will be procedural.


We currently use the following:

functions.php -> Has all functions where we define the DB instance as global.
e.g.
getcost($productid)
{
    // make $db available inside the function
    global $db;
    return $db->dlookup('pricing', 'product', 'pid = ?', array($productid));
}

init.php -> This file instantiates the DB connection
$db = new Database();

page.php -> This file 'requires' the functions.php and init.php and does the processing specific to the requirements. There will be multiple pages which will do the same, require functions.php and init.php
eg.       $rowproductcost = getcost($productid);
0
Comment
Question by:nainil
1 Comment
 
LVL 18

Accepted Solution

by:
Matthew Kelly earned 500 total points
ID: 35047945
There shouldn't be any issue with global db variable, security or performance wise.

As a reference, Wordpress, one of the most popular blogging software implements db access through a global function: http://codex.wordpress.org/Function_Reference/wpdb_Class

0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now