Re: OOP PHP with MySQLi



> What a lot of overhead and such.
> I am glad I just use global $connection; whereever I need it.

Where exactly do you find any overhead ? My project will consist out of 15
or more objects with each over 20 or 30 functions. Almost every function
will need to use a database connection. Calling global $connection at the
start of every script and function.. THAT is overhead.

I'm happy with my solution and it's a joy to work with. Currently i'm
working on the foundations wich I feel is very important (i've done 2 major
projects before) and with the upcoming PHP6 i want everything to be done by
the (right) book.


In the meanwhile i've had confirmation that this IS a good way and there
should only be a 'public' statement before function SQL.
So if any people are interested:

<?php

class My {
private static $connection;

public function SQL() {
if(empty(self::$connection)) {
self::$connection = new mysqli("localhost", "login", "password",
"database");
if(mysqli_connect_errno()) {
trigger_error("Could not connect to database !
".mysqli_connect_error()."", E_USER_ERROR);
}
}
return self::$connection;
}
}

?>

If you load the upper code in every script you can easily comunicate with
your database using
My::SQL()->query();

Best thing is that you can use this in every function or object without
having the need to call anything else.


.



Relevant Pages

  • Re: Design / best practices question
    ... what do you think the overhead is to instantiate a SQL connection? ... What I am challenging here is whether the creation of the SQL connection is really a problem. ... Under load, the pool will retain all of the connection objects, so the overhead, per call, is in the millisecond range at max and more likely to be microseconds. ... On heavily used apps, ADO.NET is constantly pulling from the connection pool, so the instantiation time is reduced tremendously. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Design / best practices question
    ... values to the database. ... what do you think the overhead is to instantiate a SQL connection? ... even with sudden heart failure on your system. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: only 11Mb/s with bcm43xx on F5?[Scanned]
    ... But because there is the overhead of encryption and decryption, ... but I do not expect it to be as fast as the wired connection. ... overhead with the wireless connection if you are using WEP or WPA. ...
    (Fedora)
  • Re: only 11Mb/s with bcm43xx on F5?[Scanned]
    ... But because there is the overhead of encryption and decryption, ... but I do not expect it to be as fast as the wired connection. ... overhead with the wireless connection if you are using WEP or WPA. ...
    (Fedora)