Prev | Current Page 168 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

In other words, to execute an SQL query using GetAll(), we wouldn??™t create a new class
instance, like in the following example (and we couldn??™t do it not only because there??™s no instance version of the
GetAll() method but also because the private constructor prevents us from instantiating the DatabaseHandler
class):
$myHandler = new DatabaseHandler();
$results = $myHandler->GetAll($sql);
Instead, static methods are called directly using the class name (using the :: notation) as follows, instead of an
object of the class (which uses the -> notation):
DatabaseHandler::GetAll($sql);
Static members of a class are internally stored by PHP using a global instance of the class. In our PDO scenario,
the advantage of storing the database connection in a static member (private static $_mHandler) is that all
database operations our site makes during one web request go through this one database connection. As explained
earlier, for performance, we prefer to use this technique instead of creating a new database connection for each
query that needs to be executed, and the support of static members of PHP allows us to implement it.
?– Note Static members are OOP-specific features that aren??™t supported by PHP 4 and older versions.
You can find a very good introduction to the OOP features in PHP 5 at http://php.net/manual/en/
language.oop5.php.


Pages:
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
perfumy fm Anteny satelitarne apartamenty przy plaży online loan for bad credit rekuperatory