<?php

/*
 * Class return connection to database
 *
 * @author: http://phpdao.com
 * @date: 27.11.2007
 */

class ConnectionFactory {

    /**
     * Zwrocenie polaczenia
     *
     * @return polaczenie
     */
    static public function getConnection() {
//        $conn = mysql_connect(ConnectionProperty::getHost(), ConnectionProperty::getUser(), ConnectionProperty::getPassword());
//        mysql_select_db(ConnectionProperty::getDatabase()) or die(mysql_error());
//        if (!$conn) {
//            throw new Exception('could not connect to database');
//        }
        $conn = mysqli_connect(ConnectionProperty::getHost(), ConnectionProperty::getUser(), ConnectionProperty::getPassword(), ConnectionProperty::getDatabase());
        if (!$conn) {
            //echo "Failed to connect to MySQL: " . mysqli_connect_error();
            throw new Exception('could not connect to database');
        }
        return $conn;
    }

    /**
     * Zamkniecie polaczenia
     *
     * @param connection polaczenie do bazy
     */
    static public function close($connection) {
        //mysql_close($connection);
        mysqli_close($connection);
    }

}

?>