Solved

Need advice on the approach of developing a web application

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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.

697 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