Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: PHP Gurus...

  1. #11
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    I use this to connect:
    PHP Code:
    class MySQL {
        public 
    $kernel$storedFetch;
        private 
    $dbInfo$dbConnection$db$debugConnection$debugInfo$storedQuery;
        
        public function 
    __construct$kernel )
        {
            
    $this->Kernel $kernel;
            
    $this->dbInfo $this->Kernel->_loadItem"MySQL""MySQL.php""Database/""Config" );
            
    $this->_bootDatabase();
        }
            
        private function 
    _bootDatabase( )
        {
            if( empty( 
    $this->dbInfo["Database"] ) !== false )
            {
                
    $this->Kernel->alert->displayAlert"warning"1003 );
                return 
    false;
            }
            
            
    $dbInfo["Username"] = ( empty( $dbInfo["Username"] ) !== false ) ? "root" $dbInfo["Username"];
            
    $dbInfo["Server"] = ( empty( $dbInfo["Server"] ) !== false ) ? "localhost" $dbInfo["Server"];
            
            
    $this->dbConnection = @mysql_connect$this->dbInfo["Server"], $this->dbInfo["Username"], $this->dbInfo["Password"] );
            
    $this->db = @mysql_select_db$this->dbInfo["Database"] );
            
            if( 
    $this->dbConnection === false || $this->db === false )
            {
                
    // Can't connect! Lets try to debug..
                
    $this->_debugConnection();
            }
        } 
    Ok that's it I am never letting you view my code over teamviewer again.

    PHP Code:
    class Database
    {
        private 
    $kernel;
        private 
    $_dbInfo;
        
        private 
    $db;
        
        public function 
    __constructKernel $kernel )
        {
            
    $this->kernel $kernel;
            
    $this->_startDbConn();
        }
        
        private function 
    _startDbConn()
        {
            
    # Grab the configuration info
            
    global $mysql;
            
            
    $this->_dbInfo $mysql;
            unset( 
    $mysql );
            
            
    $class = ( strtolower$this->_dbInfo'driver' ] ) === 'mysqli' ) ? 'clientMySQLi' 'clientMySQL' ;
            
            
    $this->kernel->loadClass$class$class '.php''/Database' );        
            
    $this->db $this->kernel->getClass$class );
            
            
    $this->db->connect$this->_dbInfo );
            
            
    $this->kernel->setClass'db'$this->db );
            
    //print_r($this->_dbInfo);
        
    }

    PHP Code:
    class clientMySQL
    {
        private 
    $kernel;
        
        private 
    $_conn;
        
        public function 
    __construct$kernel )
        {
            
    $this->kernel $kernel;
        }
        
        public function 
    connect$sql )
        {
            
    $persistent = ( $sql'persistent' ] === ) ? 'mysql_pconnect' 'mysql_connect';
            
            
    $host = ( isset( $sql'port' ] ) === true and ctype_digit$sql'port' ] ) === true ) ? $sql'hostname' ] . ':' $sql'port' ] : $sql'hostname' ];
            
            
    $this->_conn = @$persistent$host$sql'username' ], $sql'password' ] );
            
            if( 
    $this->_conn === false ) {
                
    errHandler::mysqlErrormysql_errno() );
            }
        }



    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  2. #12
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Jewish Bear View Post
    Ok that's it I am never letting you view my code over teamviewer again.

    PHP Code:
    class Database
    {
        private 
    $kernel;
        private 
    $_dbInfo;
        
        private 
    $db;
        
        public function 
    __constructKernel $kernel )
        {
            
    $this->kernel $kernel;
            
    $this->_startDbConn();
        }
        
        private function 
    _startDbConn()
        {
            
    # Grab the configuration info
            
    global $mysql;
            
            
    $this->_dbInfo $mysql;
            unset( 
    $mysql );
            
            
    $class = ( strtolower$this->_dbInfo'driver' ] ) === 'mysqli' ) ? 'clientMySQLi' 'clientMySQL' ;
            
            
    $this->kernel->loadClass$class$class '.php''/Database' );        
            
    $this->db $this->kernel->getClass$class );
            
            
    $this->db->connect$this->_dbInfo );
            
            
    $this->kernel->setClass'db'$this->db );
            
    //print_r($this->_dbInfo);
        
    }

    PHP Code:
    class clientMySQL
    {
        private 
    $kernel;
        
        private 
    $_conn;
        
        public function 
    __construct$kernel )
        {
            
    $this->kernel $kernel;
        }
        
        public function 
    connect$sql )
        {
            
    $persistent = ( $sql'persistent' ] === ) ? 'mysql_pconnect' 'mysql_connect';
            
            
    $host = ( isset( $sql'port' ] ) === true and ctype_digit$sql'port' ] ) === true ) ? $sql'hostname' ] . ':' $sql'port' ] : $sql'hostname' ];
            
            
    $this->_conn = @$persistent$host$sql'username' ], $sql'password' ] );
            
            if( 
    $this->_conn === false ) {
                
    errHandler::mysqlErrormysql_errno() );
            }
        }

    Actually, I coded that without seeing your MySQL Class ever, its only your Kernel I have seen.

  3. #13
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Oh, I hear my roflcopter engine startin', come aboard har har har.

    Ontopic: OOP is quite easy to get the hang of it, when you understand the basics my friend. You should check out php.net.

    Hi, names James. I am a web developer.

  4. #14
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Why are you typecasting everything? It's completely unnecessary.

    Quote Originally Posted by Protege View Post
    PHP Code:
    class database
    {
        public 
    $core;
        
        public function 
    connect()
        {
            
    $dbConnect = ( bool ) mysql_connect$this->core->__dbHost$this->core->__dbUsername$this->core->__dbPassword );
            
            if( 
    $dbConnect !== TRUE )
            {
                
    $this->core->___errorMessage = ( string ) $this->core->languages->___language'DbBadConnect' );
                return 
    FALSE;
            }
            
            
    $dbSelectDb = ( bool ) mysql_select_db$this->core->__dbDatabase );
            
            if( 
    $dbSelectDb !== TRUE )
            {
                
    $this->core->___errorMessage = ( string ) $this->core->languages->___language'dbBadDatabase' );
                return 
    FALSE;
            }
            
            return 
    TRUE;
        }
    /* ...... */

    ya can do that instead if you want to.


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  5. #15
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Bcuz its good practice... even though PHP auto interprets it all.
    Hi, names James. I am a web developer.

  6. #16
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Quote Originally Posted by Protege View Post
    Bcuz its good practice... even though PHP auto interprets it all.
    It's only good practice in certain circumstances..not when the returned value is always going to be a specific data type.

  7. #17
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    And when I've used it, the values could return a different type than specified.
    Hi, names James. I am a web developer.

  8. #18
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Protege View Post
    And when I've used it, the values could return a different type than specified.
    PHP Code:
    $dbConnect = ( bool ) mysql_connect$this->core->__dbHost$this->core->__dbUsername$this->core->__dbPassword ); 
    Useless, it will return boolean false if there's an error so you typecast it then check to make sure it's not true :eusa_thin

    PHP Code:
    $dbSelectDb = ( bool ) mysql_select_db$this->core->__dbDatabase ); 
    Useless, it will always return a boolean type :eusa_thin


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  9. #19
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    I agree on the second part but on the first I have a mixed opinion.

    However Ive used an if statement to check that it isn't true, so it is useless in that instance, unless I was to check it was equal to true it would be the correct way.
    Hi, names James. I am a web developer.

  10. #20
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    This isn't really helping the thread starter. This is way too complex for a begginner. Seriously.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •