extra-mysql-functies

Gesponsorde koppelingen

PHP script bestanden

  1. extra-mysql-functies

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
//check if a query has results
function mysql_results_empty($query){
    $result = mysql_query($query);
    if(mysql_num_rows($result) != 0){
        return true;
    }
else{
        return false;
    }
}

//connect and select db
function mysql_conn($host,$user,$pass,$db){
    $conn = mysql_connect($host,$user,$pass);
    if (!$conn) {
        return false;
        exit;
    }

    
    $db_selected = mysql_select_db($db, $conn);
    if (!$db_selected) {
        return false;
        exit;
    }

    return true;
}

//returns the average of all the querty results
function mysql_average($query,$num_col,$weight = 0){
    $a = 0;
    $tot = 0;
    $result = mysql_query($query);
    while ($array = mysql_fetch_array($result)) {
        if($weight == 0){
            $tot = $tot + $array[$num_col];
            $a++;
        }
else{
            $tot = $tot + $array[$num_col] * $array[$weight];
            $a = $a + $array[$weight];
        }
    }

    $gem = $tot / $a;
    return $gem;
}

//returns the id of the inserted querty
function mysql_query_id($query){
    mysql_query($query);
    return mysql_insert_id();
}

//sprintf for mysql_querty
function mysql_queryf($query) {
    if (func_num_args() > 1) {
        $args = func_get_args();
        $query = call_user_func_array("sprintf",$args);
    }

    return mysql_query($query);
}


//@ gerjo
function mysql_fetch_query($sql, $return_row = false) {
    $res = mysql_query($sql);
    return (mysql_error() != '') ? false:(($return_row) ? mysql_fetch_row($res) : mysql_fetch_assoc($res));
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.