Advertisement

06.08.2008 at 10:24AM PDT, ID: 23467406
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

making mysql wrapper accessible globaly

Asked by AlexanderR in PHP Scripting Language, PHP and Databases

Tags: ,

Hello.
I am trying to make my own mysql wrapper that i can use for my small projects.  

I have a class MySQLWrapper that has all the methods concerning queries, sanitation, etc. as well as some statistics about the last query performed.  I am declaring the instance on the index page using $DbCon = new MySQLWrapper();  All required files are included through index page, somewhat like front controller.  Generally it works fine, but obviously i cannot access $DbCon from within other functions or classes unless i do something ugly like $GLOBALS['DbCon']->query($sqlCheckUser).  Passing $DbCon as a parameter increases the number of required parameters for all the function/method which isn't pretty either.  How else can DB be accessed by any class that needs it, while confirming with good coding practices?

P.S
I once tried to create an instance within the class which does work everywhere, something like:
private $instance_MySqlDb = null;
public function Instance() {
      if(self::$instance_MySqlDb == null) {
            self::$instance_MySqlDb = new self();
      }
      return self::$instance_MySqlDb;
}
and then access the DB through mysqlwrapper::Instance->query but got many warnings about bad practice or something.

I am still new to OOP.

btw:
I want to create my own because others miss out what i need or have something i don't need, frameworks are too big for small projects and just for practice.  So suggestions about using a premade one won't be accepted.  However, i will consider looking at premade ones if i am to learn from them only.

Thank you.Start Free Trial
[+][-]06.08.2008 at 02:03PM PDT, ID: 21739568

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP and Databases
Tags: php, 5
Sign Up Now!
Solution Provided By: dankhasis
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628