示例#1
0
function dbInsert($data, $table)
{
    global $fullSql;
    // the following block swaps the parameters if they were given in the wrong order.
    // it allows the method to work for those that would rather it (or expect it to)
    // follow closer with SQL convention:
    // insert into the TABLE this DATA
    if (is_string($data) && is_array($table)) {
        $tmp = $data;
        $data = $table;
        $table = $tmp;
        //trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE);
    }
    $sql = 'insert into ' . $table . ' (' . implode(',', array_keys($data)) . ') values(' . implode(',', dbPlaceHolders($data)) . ')';
    dbBeginTransaction();
    $result = dbQuery($sql, $data);
    if ($result) {
        $id = mysql_insert_id();
        dbCommitTransaction();
        return $id;
    } else {
        if ($table != 'Contact') {
            trigger_error('QDB - Insert failed.', E_WARNING);
        }
        dbRollbackTransaction();
        return false;
    }
}
示例#2
0
function dbInsert($data, $table)
{
    global $fullSql, $database_link;
    global $db_stats;
    // the following block swaps the parameters if they were given in the wrong order.
    // it allows the method to work for those that would rather it (or expect it to)
    // follow closer with SQL convention:
    // insert into the TABLE this DATA
    if (is_string($data) && is_array($table)) {
        $tmp = $data;
        $data = $table;
        $table = $tmp;
        // trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE);
    }
    $sql = 'INSERT INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`)  VALUES (' . implode(',', dbPlaceHolders($data)) . ')';
    $time_start = microtime(true);
    dbBeginTransaction();
    $result = dbQuery($sql, $data);
    if ($result) {
        $id = mysqli_insert_id($database_link);
        dbCommitTransaction();
        // return $id;
    } else {
        if ($table != 'Contact') {
            trigger_error('QDB - Insert failed.', E_USER_WARNING);
        }
        dbRollbackTransaction();
        // $id = false;
    }
    // logfile($fullSql);
    $time_end = microtime(true);
    $db_stats['insert_sec'] += number_format($time_end - $time_start, 8);
    $db_stats['insert']++;
    return $id;
}
示例#3
0
function dbInsert($data, $table)
{
    global $fullSql;
    // the following block swaps the parameters if they were given in the wrong order.
    // it allows the method to work for those that would rather it (or expect it to)
    // follow closer with SQL convention:
    // insert into the TABLE this DATA
    if (is_string($data) && is_array($table)) {
        $tmp = $data;
        $data = $table;
        $table = $tmp;
        print_debug('Parameters passed to dbInsert() were in reverse order.');
    }
    $sql = 'INSERT INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`)  VALUES (' . implode(',', dbPlaceHolders($data)) . ')';
    $time_start = microtime(true);
    //dbBeginTransaction();
    $result = dbQuery($sql, $data);
    if ($result) {
        // This should return true if insert succeeded, but no ID was generated
        $id = dbLastID();
        //dbCommitTransaction();
    } else {
        //dbRollbackTransaction();
        $id = FALSE;
    }
    $time_end = microtime(true);
    $GLOBALS['db_stats']['insert_sec'] += number_format($time_end - $time_start, 8);
    $GLOBALS['db_stats']['insert']++;
    return $id;
}