Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

lol php

Name: Anonymous 2009-09-25 5:49

How does look for a database connection singleton pattern?


class Config
{
    const host = "localhost";
    const user = "root";
    const pass = "saucepl0x";
    const name = "content";
}

final class Singleton extends Config
{
    protected static $connection;
    protected static $database = null;
   
    protected function Singleton () { }
    protected function __clone   () { }
   
    static function Prepare()
    {
        self::$connection = new mysqli
        (
            parent::host,
            parent::user,
            parent::pass,
            parent::name
        );
       
        if (mysqli_connect_errno())
        {
            printf
            (
                "Connection Error: %s\n ", mysqli_connect_error()
            );
        } else { echo "Databse resource found."; }
    }
   
    public static function Instance()
    {       
        if (!isset(
            self::$database)) {
            self::$database = self::Prepare();
        }
        return self::$database;
    }
}

$instance = Singleton::Instance();

Name: Anonymous 2009-09-25 5:50

Use PDO

Name: Anonymous 2009-09-25 5:57

Ah, storing password in a plain text file... now I remember why I gave up PHP.

Name: Anonymous 2009-09-25 6:03

ripoff of a real ENTERPRIZE language.

Name: Anonymous 2010-12-17 1:28

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Don't change these.
Name: Email:
Entire Thread Thread List