Solved

Need advice on the approach of developing a web application

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

803 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