PHP-Einfach.de PHP lernen leicht gemacht

Navigation
» Startseite
» Newsübersicht
» Kontakt
» Impressum

Community
» Forum
» Gästebuch

Tutorial
» PHP Tutorial
» MySQL Tutorial
» PHP
» MySQL
» Codeschnipsel

Downloads
» Einführung
» Scripts
» Command Board

Sonstiges
» md5-Generator
» Generator
» Wissenswertes

PHP lernen


Dieses Projekt wird unterstützt von
Lichteffekte Shop

 
Partner:
PHP Forum
Mathe Nachhilfe
Suchmaschinenoptimierung

Mysql-klasse (PHP5)

Zurück zur Übersicht

Im Anhang ist sie noch mal als .zip-datei.
Falls jemand Verbesserungs bzw Ideen hat, nehme Ich sie gerne entgegen.

 PHP 
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:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
<?
error_reporting
(E_ALL);

/*
    @ PHP5 Mysql-klasse 
    @ Copyright by Web Communication World (www.wccw.in)
    @ Diese Klasse darf frei unter diesem Vermerk eingesetzt, verändert und weitergegeben werden
    @ Weitere Klassen, sind auf www.wccw.in Kostenlos erhältlich


    Verwendete Funktionen:
    @ mysql_connect
    @ mysql_select_db
    @ mysql_error
    @ mysql_query
    @ mysql_fetch_array
    @ mysql_fetch_assoc
    @ mysql_fetch_object
    @ mysql_fetch_row
    @ mysql_num_rows
    @ mysql_real_escape_string
    @ mysql_free_result
    @ mysql_insert_id
    @ mysql_close
    @ htmlspecialchars
    @ trigger_error
*/








class mysql
{
    private 
$host     ''
    private 
$user     '';
    private 
$passwort     ''
    private 
$dbname     '';
    private 
$last_injection '';
    private 
$conn_id null;
    
    
    
    
    public function 
__construct($host$user$passwort$dbname)
    {
        
$this->host     $host;
        
$this->user     $user;
        
$this->passwort $passwort;
        
$this->dbname     $dbname;
        
$this->connect_mysql();
        return(
$this->conn_id);
    }
    
    
    
    private function 
connect_mysql()
    {
        
$this->conn_id mysql_connect($this->host,$this->user,$this->passwort);
        
        if(
$this->conn_id === false)
        {
            
$message  "Verbindung zur Datenbank nicht m&ouml;glich.<br />\n";
            
$message .= "Mysql-fehlermeldung: <br />\n";
            
$message .= mysql_error();
            
            
trigger_error($message);
            } 
            else 
            {
            
$this->select_db();
        }
    }
    
    
    
    private function 
select_db()
    {
        
$select mysql_select_db($this->dbname,$this->conn_id);
        
        if(
$select === false)
        {
            
$message  "Die angegebene Datenbank \"".$this->dbname."\" existiert nicht.<br />\n";
            
$message .= "Mysql-fehlermeldung: <br />\n";
            
$message .= mysql_error();
            
            
trigger_error($message);
        }
    }
    
    
    
    public function 
query($sqlcode)
    {
        
$this->last_injection mysql_query($sqlcode);
        
            if(
$this->last_injection === false)
            {
                
$message  "Fehler bei dem Ausf&uuml;hren eines Mysql-codes!<br />\n";
                
$message .= "Mysql-Code: " htmlspecialchars($sqlcodeENT_QUOTES) . "<br />\n";
                
$message .= "Mysql-fehlermeldung:<br />\n";
                
$message .= mysql_error();
                
trigger_error($message);
            }
            
        return(
$this->last_injection);
    }
    
    
    
    public function 
array_result($sql NULL, &$row '')
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
$row mysql_fetch_array($inc);
        
        return(
$row);
    }
    
    
    
    public function 
row_result($sql NULL, &$row '')
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
$row mysql_fetch_row($inc);
        
        return(
$row);
    }
    
    
    
    public function 
object_result($sql NULL, &$row '')
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
$row mysql_fetch_object($inc);
        
        return(
$row);
    }
    
    
    
    public function 
assoc_result($sql NULL, &$row '')
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
$row mysql_fetch_assoc($inc);
        
        return(
$row);
    }
    
    
    
    public function 
num_result($sql NULL)
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
$num mysql_num_rows($inc);
        
        return(
$num);
    }
    
    
    
    public function 
sql_string($string)
    {
        return(
mysql_real_escape_string($string));
    }
    
    
    
    public function 
free_result($sql NULL)
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
mysql_free_result($inc);
    }
    
    
    
    public function 
result($set 0$field 0$sql NULL, &$row '')
    {
        
$inc '';
        if(
$sql === NULL)
        {
            
$inc $this->last_injection;
            } else {
            
$inc $sql;
        }
        
        
$row mysql_result($result$set$field);
        
        return(
$row);
    }
    
    
    
    public function 
insert_id(&$row '')
    {
    
        
$row mysql_insert_id();
        
        return(
$row);
    }
    
    
    
    public function 
close_connect()
    {
        
mysql_close($this->conn_id);
    }
}



/************************************************************/
# Einfache anwendung:


$sql = new mysql("localhost","user","passwort","datenbank");

$res $sql->query("SELECT * FROM `tabelle` ORDER BY `spalte` DESC;");
while(
$row $sql->array_result($res))
{
    echo(
$row['spalte']."<br />\n");
}

$sql->free_result();

$sql->close_connect();
?>


Kommentare

Zurück zur Übersicht

Autor wccw.in

News
13.08 - » Spam im Gästebuch
Endlich Schluss mit dem Spam

08.12 - » Clanletter 2.0
Clanletter wurde komplett neu programmiert

01.09 - » Command Board 1.0 - 2.0
Das Command Board 1.0 Beta 2.0 ist erschienen


Mehr

Forum
» Entwickler Forum

» insert nach login

» Tabellenzelle zu groß







© PHP-Einfach.de 2003 - 2012