?
Solved

Need advice on the approach of developing a web application

Posted on 2011-03-06
1
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
Matthew Kelly earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

771 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