Solved

Need advice on the approach of developing a web application

Posted on 2011-03-06
1
289 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

759 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

17 Experts available now in Live!

Get 1:1 Help Now