Location: PHPKode > projects > PhpBlock > A9.8/script/connect.php
<?php
include_once $PATH_TO_CODE."/script/log.class.php";
include_once $PATH_TO_CODE."/script/event/precommitevent.class.php";

//execute une requ�te et termine le script si l'éxécution de la requ�te est fausse
function executer($req, $parCanFailed=false) {
    Log::debug("executer($req)");
    $locCountQueryTried = 0;
    $res=false;
    while(!$res && $locCountQueryTried < 10) {
        $res = mysql_query($req);
        $locCountQueryTried++;
        if(!$res && !$parCanFailed) {
            break;
        }
    }
    if(!$res) {
        echo "Request $req failed<br><br>";
        echo mysql_error();
        if(!$parCanFailed) {
            $locInnoDBStatusRes = mysql_query("SHOW ENGINE INNODB STATUS");
            while($row = mysql_fetch_array($locInnoDBStatusRes)) {
                echo $row[0];
            }
            exit;
        }
    }
	return $res;
}
$gloDatabaseLinkId;
function connectToDB(){
    //se connecte à la base de donnée $db et renvoie une connection en cas de réussite et un message d'erreur en cas d'échec
	$db = Site::$DB_NAME;
	$hostName = Site::$DB_HOSTNAME;
	$userName = Site::$DB_USERNAME;
	$password = Site::$DB_PASSWORD;
    global $gloDatabaseLinkId;
    $gloDatabaseLinkId = mysql_connect("$hostName", "$userName", "$password");
	if(!$gloDatabaseLinkId) {
	    echo "CAN'T CONNECT TO DATABASE";
        exit;
	}
	mysql_select_db($db, $gloDatabaseLinkId);
	executer("SET AUTOCOMMIT=0");
}
function commit() {
    ObjectManager::getInstance()->notifyEvent(new PreCommitEvent());
    executer("COMMIT");
}
function closeDB() {
    global $gloDatabaseLinkId;
    mysql_close($gloDatabaseLinkId);
}
connectToDB();
?>
Return current item: PhpBlock