/** * connect to a database * @param string $type database type * @param string $host host name or a location of ini file * @param string $user user name * @param string $pass password * @param string $db database name * * @access public * @static * @return bool true if connection was successful; */ public static function connect($type, $host, $user = false, $pass = false, $db = false) { if ($user == false && file_exists($host)) { $db = new IniObject($host); if (!isset($db->user) || !isset($db->password) || !isset($db->database) || !isset($db->host)) { throw new NewDaoException("Ini File Does Not contain all required definitions"); } $host = $db->host; $user = $db->user; $pass = $db->password; $db = $db->database; } elseif (!$user || !$pass || !$db) { throw new NewDaoException("not all required variables were set"); } switch ($type) { case "mysql": $link = mysql_connect($host, $user, $pass); mysql_select_db($db, $link); if (mysql_error($link)) { throw new NewDaoException("Mysql Error:" . mysql_error($link)); } self::$_connected = true; self::$_link = $link; return true; break; default: $link = new mysqli($host, $user, $pass, $db); if (mysqli_errno($link)) { throw new NewDaoException("Mysqli Error:" . mysqli_error($link)); } self::$_connected = true; self::$_link = $link; return true; break; } throw new NewDaoException("Bad Database Type"); }