Database connection class suggestions
<p>I created this class to connect to my database and read somewhere that having different users for the connection is the most secure. So I made a user for the four different options I use at the moment one for Update, Select, Delete, and Insert. I wasn't really sure if it was necessary to create a user for each one of these. I am basically wondering what I could do to improve this class. I know these questions have appeared a lot on here but everyone's class seems to be different, so I figured I'd ask.</p>

<p>Here is the pastebin for the code.. Its very long otherwise I'd just post it here. If pastebin is an issue I'll add the code anyway. </p>

<p>(edit by ninetwozero: put the code inline)</p>

<pre><code>&lt;?php

    class DB_Connection { 

        //Subject to change 
        protected $_DATABASE = '#';
        protected $_HOST       = '#';

        protected $_SELECT = array( 'connection' =&gt; null,
                                  'user'    =&gt; '#',
                                  'pass'    =&gt; '#', 
                                  'alive'   =&gt; FALSE,
                                  'thread'  =&gt; '' );

        protected $_INSERT = array( 'connection' =&gt; null,
                                  'user'    =&gt; '#',
                                  'pass'    =&gt; '#',
                                  'alive'   =&gt; FALSE,
                                  'thread'  =&gt; '' );

        protected $_DELETE = array( 'connection' =&gt; null,
                                  'user'    =&gt; '#',
                                  'pass'    =&gt; '#',
                                  'alive'   =&gt; FALSE,
                                  'thread'  =&gt; '' );

        protected $_UPDATE = array( 'connection' =&gt; null,
                                  'user'    =&gt; '#',
                                  'pass'    =&gt; '#',
                                  'alive'   =&gt; FALSE,
                                  'thread'  =&gt; '' );

        /**
         * Take an input and create that connection and connect to the database
         * using the appropriate logins
         * @param $type - Type of connection; SELECT, UPDATE, DELETE, INSERT
         */
        public function __construct( $type ) {

            switch($type) {
                case "SELECT":

                    // Create the connection 
                    $this-&gt;_SELECT['connection'] = new mysqli($this-&gt;_HOST,
                                                              $this-&gt;_SELECT['user'],
                                                              $this-&gt;_SELECT['pass'],
                                                              $this-&gt;_DATABASE );
                    // State that the connection is alive                                 
                    $this-&gt;_SELECT['alive'] = TRUE;

                    // Put in the thread ID that is created when the connection is established
                    $this-&gt;_SELECT['thread'] = $this-&gt;_SELECT['connection']-&gt;thread_id;

                    // Verify that the connection was successfull                                         
                    if($this-&gt;_SELECT['connection']-&gt;connect_error) {
                        die('Connection error: ' . $this-&gt;_SELECT['connection']-&gt;connect_errorno . ' ' . 
                                                   $this-&gt;_SELECT['connection']-&gt;connect_error );
                        //TODO Create better error handling
                    } else {
                        echo "connection worked somehow.&lt;br /&gt;";
                    }

                case "INSERT":
                    // Create the connection 
                    $this-&gt;_INSERT['connection'] = new mysqli($this-&gt;_HOST,
                                                          $this-&gt;_INSERT['user'],
                                                          $this-&gt;_INSERT['pass'],
                                                          $this-&gt;_DATABASE );
                    // State that the connection is alive
                    $this-&gt;_INSERT['alive'] = TRUE;

                    // Put in the thread ID that is created when the connection is establishedq
                    $this-&gt;_INSERT['thread'] = $this-&gt;_INSERT['connection']-&gt;thread_id;

                    // Verify that the connection was successfull                                     
                    if($this-&gt;_INSERT['connection']-&gt;connect_error) {
                        die('Connection error: ' . $this-&gt;_INSERT['connection']-&gt;connect_errorno . ' ' . 
                                                   $this-&gt;_INSERT['connection']-&gt;connect_error );
                        //TODO Create better error handling
                    } else {
                        echo "connection worked somehow.&lt;br /&gt;";
                    }

                case "DELETE":
                    // Create the connection 
                    $this-&gt;_DELETE['connection'] = new mysqli($this-&gt;_HOST,
                                                          $this-&gt;_DELETE['user'],
                                                          $this-&gt;_DELETE['pass'],
                                                          $this-&gt;_DATABASE );
                    // State that the connection is alive
                    $this-&gt;_DELETE['alive'] = TRUE;

                    // Put in the thread ID that is created when the connection is establishedq
                    $this-&gt;_DELETE['thread'] = $this-&gt;_DELETE['connection']-&gt;thread_id;

                    // Verify that the connection was successfull 
                    if($this-&gt;_DELETE['connection']-&gt;connect_error) {
                        die('Connection error: ' . $this-&gt;_DELETE['connection']-&gt;connect_errorno . ' ' . 
                                                   $this-&gt;_DELETE['connection']-&gt;connect_error );
                        //TODO Create better error handling
                    } else {
                        echo "connection worked somehow.&lt;br /&gt;";
                    }   

                case "UPDATE":
                    // Create the connection 
                    $this-&gt;_UPDATE['connection'] = new mysqli($this-&gt;_HOST,
                                                          $this-&gt;_UPDATE['user'],
                                                          $this-&gt;_UPDATE['pass'],
                                                          $this-&gt;_DATABASE );
                    // State that the connection is alive
                    $this-&gt;_UPDATE['alive'] = TRUE;

                    // Put in the thread ID that is created when the connection is establishedq
                    $this-&gt;_UPDATE['thread'] = $this-&gt;_UPDATE['connection']-&gt;thread_id;

                    // Verify that the connection was successfull 
                    if($this-&gt;_UPDATE['connection']-&gt;connect_error) {
                        die('Connection error: ' . $this-&gt;_UPDATE['connection']-&gt;connect_errorno . ' ' . 
                                                   $this-&gt;_UPDATE['connection']-&gt;connect_error );
                        //TODO Create better error handling
                    } else {
                        echo "connection worked somehow.&lt;br /&gt;";
                    }   

            }// END CASE

        }// END _construct


        public function get_Select_Con() {
            return $this-&gt;_SELECT['connection'];
        }
        public function get_Insert_Con() {
            return $this-&gt;_INSERT['connection'];
        }
        public function get_Delete_Con() {
            return $this-&gt;_DELETE['connection'];
        }
        public function get_Update_Con() {
            return $this-&gt;_UPDATE['connection'];
        }


        /**
         * Kill the threads and close the connection
         */
        public function __destruct() {
            if ($this-&gt;_SELECT['alive'] == TRUE) {
                $this-&gt;_SELECT['connection']-&gt;kill($this-&gt;_SELECT['thread']);
                $this-&gt;_SELECT['connection']-&gt;close();
                echo " thread killed and connection closed";
            }
            if ($this-&gt;_INSERT['alive'] == TRUE) {
                $this-&gt;_INSERT['connection']-&gt;kill($this-&gt;_INSERT['thread']);
                $this-&gt;_INSERT['connection']-&gt;close();
                echo " thread killed and connection closed";
            }
            if ($this-&gt;_DELETE['alive'] == TRUE) {
                $this-&gt;_DELETE['connection']-&gt;kill($this-&gt;_DELETE['thread']);
                $this-&gt;_DELETE['connection']-&gt;close();
                echo " thread killed and connection closed";
            }
            if ($this-&gt;_UPDATE['alive'] == TRUE) {
                $this-&gt;_UPDATE['connection']-&gt;kill($this-&gt;_UPDATE['thread']);
                $this-&gt;_UPDATE['connection']-&gt;close();
                echo " thread killed and connection closed";
            }
        }// END _destruct
    }
?&gt;
</code></pre>

<p><a href="http://pastebin.com/F4e4Yz5r" rel="nofollow">http://pastebin.com/F4e4Yz5r</a></p>
