Пример #1
0
function MySqlQuery($SqlString, $SessionId = "", $NonSecure = "")
{
    // Можно передавать соединение по ссылке &$ConnectionId  MySqlQuery($SqlString,&$ConnectionId, $SessionId,$NonSecure);
    //
    // вызов  MySqlQuery('...',&$ConnectionId, ...);
    // echo $ConnectionId;
    $ConnectionId = CSql::getConnection();
    $t1 = microtime(true);
    $rs = mysql_query($SqlString, $ConnectionId);
    CMmbLogger::addInterval('query', $t1);
    if (!$rs) {
        $err = mysql_error();
        CMmbLogger::e('MySqlQuery', "sql error: '{$err}' \r\non query: '{$SqlString}'");
        echo $err;
        CSql::closeConnection();
        die;
        return -1;
    }
    // Если был insert - возвращаем последний id
    if (strpos($SqlString, 'insert') !== false) {
        $rs = mysql_insert_id($ConnectionId);
        //  echo ' NewId '.$rs;
    }
    //CSql::closeConnection(); // try not closing, use global
    return $rs;
}