/** * create object first time * * @access public * @author GDev Team <*****@*****.**> * @since 23/08/2005 * @param mixed $dsn connection data as string or array * @param array $options runtime options * @return mixed database object or exception */ public static function factory($dsn, $options = false) { /** * create options array */ if (!is_array($options)) { $options = array('persistent' => $options); } /** * set the dsn array */ try { $mydsn = self::parse_dsn($dsn); } catch (gdatabase_exception $e) { printf('database dsn: %s', $e->custom_message()); } /** * make dbtype lower case */ $mydbtype = strtolower($mydsn['dbtype']); /** * include specific database class file */ if (isset($options['debug']) and $options['debug'] > 0) { require_once LIB_PATH . 'gdatabase/gdatabase_' . $mydbtype . '.class.php'; } else { @(require_once LIB_PATH . 'gdatabase/gdatabase_' . $mydbtype . '.class.php'); } /** * define class name */ $classname = 'gdatabase_' . $mydbtype; /** * if class does not exist throw new exception */ if (!class_exists($classname)) { throw new gdatabase_exception('specific database class does not exist'); } /** * create object of the specific database class */ try { @($obj = new $classname()); } catch (gdatabase_exception $e) { printf('database %s: %s', $mydbtype, $e->custom_message()); } /** * set the options */ try { foreach ($options as $option => $value) { $obj->set_option($option, $value); } } catch (gdatabase_exception $e) { printf('database options: %s', $e->custom_message()); } /** * write object to instance holder */ return self::$ginstance = $obj; }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /** * check php version */ if (0 > version_compare(PHP_VERSION, '5')) { die('This file was generated for PHP 5'); } /** * include config data */ require_once dirname(__FILE__) . '/config.php'; /** * include base class files */ require_once LIB_PATH . 'gdatabase.class.php'; /** * try to create database object */ try { $options = array('debug' => DEBUG); $db = gdatabase::factory(DB_DSN, $options); } catch (gdatabase_exception $e) { printf('database: %s', $e->custom_message()); }