Location: PHPKode > projects > PHPKode - PHPGuestbook > kode_connect_db.php
<?php

    function conn_Db() {

	switch (DB_TYPE) {
	    // mysql connect
	    case 'mysql' :
		$db = new SQL();
                $db->adapter = "mysql";
                $db->options["host"] = MYSQL_HOST;
                $db->options["port"] = MYSQL_PORT;
                $db->options["database"] = MYSQL_DB_NAME;
                $db->options["username"] = MYSQL_USERNAME;
                $db->options["password"] = MYSQL_PASSWORD;
                $db->connectDB();
                if(!empty ($db->errorMessage)){
                        die($db->errorMessage);
                }

		$db->selectDB($db->db);
		break;

	    // SQLite connect
	    case 'sqlite':
                $db = new SQL();
                $db->adapter = "sqlite";
                $db->options["database"] = './data/'.SQLITE_DB_NAME;
                $db->connectDB();
                
                if(!empty ($db->errorMessage)){
                        die($db->errorMessage);
                }
		break;
	}

        if(!isset ($db)){
            die("Please set database type to 'mysql' or 'sqlite'.");
        }
	
	return $db;
    }

?>
Return current item: PHPKode - PHPGuestbook