Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
A basic pdo database class
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="SeanRog" data-source="post: 359270" data-attributes="member: 585"><p>Use the same connection trough out the script.</p><p></p><p>Take my database handler as an example:</p><p>[CODE]</p><p>/**</p><p>* @var Database\Connection</p><p>*/</p><p>private static $connection;</p><p></p><p>/**</p><p>* @return Database\Connection</p><p>*/</p><p>public static function GetConnection()</p><p>{</p><p> if(is_null(self::$connection))</p><p> {</p><p></p><p> // Connect to database</p><p> $credentials = \App\Config\Database::GetAll();</p><p> self::$connection = new Database\Connection(</p><p> $credentials['dsn'],</p><p> $credentials['username'],</p><p> $credentials['password'],</p><p> isset($credentials['options'])?$credentials['options']:null</p><p> );</p><p></p><p> // Set exceptions error mode</p><p> self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);</p><p></p><p> }</p><p></p><p> return self::$connection;</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="SeanRog, post: 359270, member: 585"] Use the same connection trough out the script. Take my database handler as an example: [CODE] /** * @var Database\Connection */ private static $connection; /** * @return Database\Connection */ public static function GetConnection() { if(is_null(self::$connection)) { // Connect to database $credentials = \App\Config\Database::GetAll(); self::$connection = new Database\Connection( $credentials['dsn'], $credentials['username'], $credentials['password'], isset($credentials['options'])?$credentials['options']:null ); // Set exceptions error mode self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } return self::$connection; } [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
A basic pdo database class
Top