eris-database-class

Gesponsorde koppelingen

PHP script bestanden

  1. eris-database-class

« 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php

class db {
//database class
//maak verbinding

    static $result;
    //$server = database server
    //$user = mysql username
    //$pass = mysql password
    //$db = database name
    //function wil return a link can be used for multiple links to 2 or more databases

    public function connect($server,$user,$pass,$db){
        //maak verbinding met database
        $link = @mysqli_connect($server,$user,$pass) or trigger_error('No valid user name or password or server is not running',E_USER_WARNING);
        if($c = @mysqli_select_db($link,$db) or trigger_error('No valid database name',E_USER_WARNING)){
              return $link;
        }
else{
            return false;
        }
        
    }

    
    //afhandeling van de database rotzooi
    //private not able to request form out side
    //$sql = sql code
    //$link = link identifer

        private function query_exec($sql,$link){
        //voer query uit
        
            $out = mysqli_query($link,$sql) or trigger_error(mysqli_errno($link) .':'.mysqli_error($link),E_USER_WARNING);
        return $out;
    }

    //recive a row or a muli dimen array
    //publik
    //$sql = sql code
    //$link = link identifer
    //$array = return a arry if true (NO required)
    //$values = array with all values that has to be protected by mysqli_real_escape_string()

    public function get_row($sql,$link,$array = false,$values = ''){
        //voer query uit
        if(!empty($values)){
        $new = explode('?',$sql);
        $sql = '';
        $i = 0;
        foreach($values as $value){
            $sql .= $new[$i] . mysqli_real_escape_string($link,$values[$i]);
            $i++;
            }

        $sql .= $new[$i];
        }

        db::$result = db::query_exec($sql,$link);
        if(!db::$result){
            return false;
        }
else{
           if($array != true){
                return mysqli_fetch_assoc(db::$result);
            }
else{
              $rows = array();
              while($row = mysqli_fetch_assoc(db::$result)){
                $rows[] = $row;
            }

            return $rows;
            }
        }    
    }

    //count rows
    //public
    //$sql = Sql code not required if empty it will use the last restored restult for query
    //$link = link identifer
    //$values = array with all values that has to be protected by mysqli_real_escape_string()

    public    function num_row($sql = '',$link,$values = ''){
    if(!empty($sql)){

        //voer query uit
        if(!empty($values)){
        $new = explode('?',$sql);
        $sql = '';
        $i = 0;
        foreach($values as $value){
            $sql .= $new[$i] . mysqli_real_escape_string($link,$values[$i]);
            $i++;
            }

        $sql .= $new[$i];
        }

          db::$result = db::query_exec($sql,$link);
    }

    return mysqli_num_rows(db::$result);
    }

    
    //insert a row
    //$table = table name
    //$value = value has to be a array for easy data handling
    //$link = link identifer
    //$date = INT if you need to insert the date use a number if 0 it will be not used. use the key for the array because it runs on a loop...


    public    function insert_row($table,$value,$link,$date = 0)
        {
       $sql = 'INSERT INTO '.$table.' SET';
                $i = 1;
                foreach($value as $label => $text){
                if($date == $i && $date > 0){    
                $sql.= ' '.$label .'= NOW( ),';
                }
else{
                $sql.= ' '.$label.'="'.mysqli_real_escape_string($link,$text).'",';
                }

                $i++;
                }

                $sql = substr($sql, 0, -1);
                $res = db::query_exec($sql,$link);
                if($res == false){
                  return false;
                }
else{
                    return mysqli_insert_id($link);
                }  
        }

    //update a row
    //public
    //$table = table name
    //$key = key name of the update key (Normaly a primary key)
    //$id = value that has to be selected. EG UPDATE table set a = 1 WHERE key = id
    //if $id you need to udate multiple rows you can enter the id as array
    //$value = value has to be a array for easy data handling
    //$link = link identifer
    //$date = INT if you need to insert the date use a number if 0 it will be not used. use the key for the array because it runs on a loop...


    public    function update_row($table,$key,$id,$value,$link,$date = 0){
                   $sql = 'UPDATE '.$table.' SET';
                $i = 1;
                foreach($value as $label => $text){
                if($date == $i){    
                $sql.= ' '.$label .'= NOW( ),';
                }
else{
                $sql.= ' '.$label.'="'.mysqli_real_escape_string($link,$text).'",';
                }

                $i++;
                }

                $sql = substr($sql, 0, -1);
                if(is_array($id)){
                  $sql.= ' WHERE '.$key.' IN ('.implode(',',$id).')';
                  }
else{
                $sql.= ' WHERE '.$key.' = '.$id;
              }

        
                $res = db::query_exec($sql,$link);
                if($res == false){
                  return false;
                }
else{
                    
                    return mysqli_affected_rows($link);
                }
        }

        //verwijder een rij
            //update a row
    //public
    //$table = table name
    //$key = key name of the update key (Normaly a primary key)
    //$id = value that has to be selected. EG UPDATE table set a = 1 WHERE key = id
    //if $id you need to udate multiple rows you can enter the id as array
    //$link = link identifer

    public        function delete_row($table,$key,$id,$link){
        if(is_array($id)){
          $sql = 'DELETE FROM '.$table.' WHERE '.$key.' IN ('.implode(',',$id).')';
        }
else{
          $sql = 'DELETE FROM '.$table.' WHERE '.$key.' = "'.$id.'"';
        }

        //voer query uit
        $out = db::query_exec($sql,$link);
        if($out == false){
          return false;
        }
else{
                    return mysqli_affected_rows($link);
        }
        }
    
        //get_result
        //alleen voor 1 waarde geschikt omdat het zeer on economisch is...
        //public
        //$sql = sql code    
         //$link = link identifer
        //$field = field ( default 0) no name has to be int
        //$values = array with all protected values for mysql_real_escape_string

     public function get_result($sql,$link,$values = '',$field = 0){
        //voeg de waardes toe...
        if(!empty($values)){
        $new = explode('?',$sql);
        $sql = '';
        $i = 0;
        foreach($values as $value){
            $sql .= $new[$i] . mysqli_real_escape_string($link,$values[$i]);
            $i++;
            }

        $sql .= $new[$i];
        }

            $res = db::query_exec($sql,$link);
            $out = mysqli_fetch_array($res);
            return $out[$field];
        }

    //exec as query exec only now public some casses use full
    //sql code
    //$link = link identifer

    public function exec($sql,$link){
        //voer query uit
          $res = db::query_exec($sql,$link);
        if(!$res){
            return false;
        }
else{
              return true;
        }
        
    }
    }

    
?>

 
 

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.