note 108041 deleted from function.define by cmb

From: Date: Tue, 31 Mar 2020 12:38:10 +0000
Subject: note 108041 deleted from function.define by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214396@lists.php.net to get a copy of this message
Note Submitter: kriscraig at php dot net ---- Some people like to have an ambiguous, engine-agnostic database include specified by assigning a single config variable to one of a series of constants. Unfortunately, this can easily become needlessly clunky if these defines are handled in an included config.php file, since more than one hook will throw an ugly "already defined" error. Here's a simple way to accomplish this architectural model without having to create a bunch of clumsy sanity checks that compromise scalability: <?php /* Available databases. --Kris */ $dbengines = array(); $dbengines[] = "mysql"; $dbengines[] = "mysqli"; $dbengines[] = "pgsql"; foreach ( $dbengines as $engine ) { if ( !defined( "_" . strtoupper( $engine ) . "_" ) ) { define( "_" . strtoupper( $engine ) . "_", $engine ); } } /* Which database engine shall we use? --Kris */ $sql_type = _MYSQLI_; ?> Then, somewhere later in the stack.... <?php /* Include the file with the desired sql class. --Kris */ require_once( $sql_type . ".php" ); /* Now you can use the same code for any supported db engine. --Kris */ $sql = new sql(); $res = $sql->query( .... );

« previous php.notes (#214396) next »