Rev 4 | Rev 8 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4 | Rev 5 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | // TODO: test everything |
3 | // TODO: test everything |
4 | // TODO: return values? |
4 | // TODO: return values? |
5 | // TODO: check if we matched all stuff mentioned here: https://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html |
5 | // TODO: check if we matched all stuff mentioned here: https://www.phpclasses.org/blog/package/9199/post/3-Smoothly-Migrate-your-PHP-Code-using-the-Old-MySQL-extension-to-MySQLi.html |
6 | 6 | ||
7 | $vts_mysqli = null; |
7 | $vts_mysqli = null; |
8 | 8 | ||
9 | // Liefert die Anzahl betroffener Datensätze einer vorhergehenden MySQL Operation |
9 | // Liefert die Anzahl betroffener Datensätze einer vorhergehenden MySQL Operation |
10 | function mysql_affected_rows($link_identifier=NULL) { |
10 | function mysql_affected_rows($link_identifier=NULL) { |
11 | global $vts_mysqli; |
11 | global $vts_mysqli; |
12 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
12 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
13 | if (is_null($li)) throw new Exception("Cannot execute mysql_affected_rows(). No valid connection to server."); |
13 | if (is_null($li)) throw new Exception("Cannot execute mysql_affected_rows(). No valid connection to server."); |
14 | 14 | ||
15 | return $li->affected_rows; |
15 | return $li->affected_rows; |
16 | } |
16 | } |
17 | 17 | ||
18 | // Liefert den Namen des Zeichensatzes |
18 | // Liefert den Namen des Zeichensatzes |
19 | function mysql_client_encoding($link_identifier=NULL) { |
19 | function mysql_client_encoding($link_identifier=NULL) { |
20 | global $vts_mysqli; |
20 | global $vts_mysqli; |
21 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
21 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
22 | if (is_null($li)) throw new Exception("Cannot execute mysql_client_encoding(). No valid connection to server."); |
22 | if (is_null($li)) throw new Exception("Cannot execute mysql_client_encoding(). No valid connection to server."); |
23 | 23 | ||
24 | return $li->character_set_name(); |
24 | return $li->character_set_name(); |
25 | } |
25 | } |
26 | 26 | ||
27 | // Schließt eine Verbindung zu MySQL |
27 | // Schließt eine Verbindung zu MySQL |
28 | function mysql_close($link_identifier=NULL) { |
28 | function mysql_close($link_identifier=NULL) { |
29 | global $vts_mysqli; |
29 | global $vts_mysqli; |
30 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
30 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
31 | if (is_null($li)) throw new Exception("Cannot execute mysql_close(). No valid connection to server."); |
31 | if (is_null($li)) throw new Exception("Cannot execute mysql_close(). No valid connection to server."); |
32 | 32 | ||
33 | return $li->close(); |
33 | return $li->close(); |
34 | } |
34 | } |
35 | 35 | ||
36 | // Öffnet eine Verbindung zu einem MySQL-Server |
36 | // Öffnet eine Verbindung zu einem MySQL-Server |
37 | function mysql_connect($server=null, $username=null, $password=null, $new_link=false, $client_flags=0) { |
37 | function mysql_connect($server=null, $username=null, $password=null, $new_link=false, $client_flags=0) { |
38 | global $vts_mysqli; |
38 | global $vts_mysqli; |
39 | $ary = explode(':', $server); |
39 | $ary = explode(':', $server); |
40 | $host = $ary[0]; |
40 | $host = $ary[0]; |
41 | $ini_port = ini_get("mysqli.default_port"); |
41 | $ini_port = ini_get("mysqli.default_port"); |
42 | $port = isset($ary[1]) ? (int)$ary[1] : ($ini_port ? (int)$ini_port : 3306); |
42 | $port = isset($ary[1]) ? (int)$ary[1] : ($ini_port ? (int)$ini_port : 3306); |
43 | if (is_null($server)) $port = ini_get("mysqli.default_host"); |
43 | if (is_null($server)) $port = ini_get("mysqli.default_host"); |
44 | if (is_null($username)) $port = ini_get("mysqli.default_user"); |
44 | if (is_null($username)) $port = ini_get("mysqli.default_user"); |
45 | if (is_null($password)) $port = ini_get("mysqli.default_password"); |
45 | if (is_null($password)) $port = ini_get("mysqli.default_password"); |
46 | $vts_mysqli = new mysqli($host, $username, $password, /*dbname*/'', $port, ini_get("mysqli.default_socket")); |
46 | $vts_mysqli = new mysqli($host, $username, $password, /*dbname*/'', $port, ini_get("mysqli.default_socket")); |
47 | return (empty($vts_mysqli->connect_error) && ($vts_mysqli->connect_errno == 0)) ? $vts_mysqli : false; |
47 | return (empty($vts_mysqli->connect_error) && ($vts_mysqli->connect_errno == 0)) ? $vts_mysqli : false; |
48 | } |
48 | } |
49 | 49 | ||
50 | // Anlegen einer MySQL-Datenbank |
50 | // Anlegen einer MySQL-Datenbank |
51 | function mysql_create_db($database_name, $link_identifier=NULL) { |
51 | function mysql_create_db($database_name, $link_identifier=NULL) { |
52 | global $vts_mysqli; |
52 | global $vts_mysqli; |
53 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
53 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
54 | if (is_null($li)) throw new Exception("Cannot execute mysql_create_db(). No valid connection to server."); |
54 | if (is_null($li)) throw new Exception("Cannot execute mysql_create_db(). No valid connection to server."); |
55 | 55 | ||
56 | return mysql_query("CREATE DATABASE `$database_name`", $li) !== false; |
56 | return mysql_query("CREATE DATABASE `$database_name`", $li) !== false; |
57 | } |
57 | } |
58 | 58 | ||
59 | // Bewegt den internen Ergebnis-Zeiger |
59 | // Bewegt den internen Ergebnis-Zeiger |
60 | function mysql_data_seek($result, $row_number) { |
60 | function mysql_data_seek($result, $row_number) { |
61 | if (!$result) { |
61 | if (!$result) { |
62 | $err = mysql_error(); |
62 | $err = mysql_error(); |
63 | throw new Exception("Called mysql_data_seek() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
63 | throw new Exception("Called mysql_data_seek() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
64 | } |
64 | } |
65 | return $result->data_seek($row_number) !== false; |
65 | return $result->data_seek($row_number) !== false; |
66 | } |
66 | } |
67 | 67 | ||
68 | // Liefert Schema Namen vom Aufruf von mysql_list_dbs |
68 | // Liefert Schema Namen vom Aufruf von mysql_list_dbs |
69 | function mysql_db_name($result, $row, $field=NULL) { |
69 | function mysql_db_name($result, $row, $field=NULL) { |
70 | if (!$result) { |
70 | if (!$result) { |
71 | $err = mysql_error(); |
71 | $err = mysql_error(); |
72 | throw new Exception("Called mysql_db_name() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
72 | throw new Exception("Called mysql_db_name() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
73 | } |
73 | } |
74 | $result->data_seek($row); |
74 | $result->data_seek($row); |
75 | return mysql_fetch_array($result)[is_null($field) ? 0 : $field]; |
75 | return mysql_fetch_array($result)[is_null($field) ? 0 : $field]; |
76 | } |
76 | } |
77 | 77 | ||
78 | // Selektiert ein Schema und führt in ihm Anfrage aus |
78 | // Selektiert ein Schema und führt in ihm Anfrage aus |
79 | function mysql_db_query($database, $query, $link_identifier=NULL) { |
79 | function mysql_db_query($database, $query, $link_identifier=NULL) { |
80 | global $vts_mysqli; |
80 | global $vts_mysqli; |
81 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
81 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
82 | if (is_null($li)) throw new Exception("Cannot execute mysql_db_query(). No valid connection to server."); |
82 | if (is_null($li)) throw new Exception("Cannot execute mysql_db_query(). No valid connection to server."); |
83 | 83 | ||
84 | mysql_select_db($database, $li); |
84 | mysql_select_db($database, $li); |
85 | return mysql_query($query, $li); |
85 | return mysql_query($query, $li); |
86 | // Note: The mysql_*() implementation defines, that we will not jump back to our original DB |
86 | // Note: The mysql_*() implementation defines, that we will not jump back to our original DB |
87 | } |
87 | } |
88 | 88 | ||
89 | // Löschen eines Schemas |
89 | // Löschen eines Schemas |
90 | function mysql_drop_db($database_name, $link_identifier=NULL) { |
90 | function mysql_drop_db($database_name, $link_identifier=NULL) { |
91 | global $vts_mysqli; |
91 | global $vts_mysqli; |
92 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
92 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
93 | if (is_null($li)) throw new Exception("Cannot execute mysql_drop_db(). No valid connection to server."); |
93 | if (is_null($li)) throw new Exception("Cannot execute mysql_drop_db(). No valid connection to server."); |
94 | 94 | ||
95 | return mysql_query("DROP DATABASE `$database_name`", $li) !== false; |
95 | return mysql_query("DROP DATABASE `$database_name`", $li) !== false; |
96 | } |
96 | } |
97 | 97 | ||
98 | // Liefert die Nummer einer Fehlermeldung einer zuvor ausgeführten MySQL Operation |
98 | // Liefert die Nummer einer Fehlermeldung einer zuvor ausgeführten MySQL Operation |
99 | function mysql_errno($link_identifier=NULL) { |
99 | function mysql_errno($link_identifier=NULL) { |
100 | global $vts_mysqli; |
100 | global $vts_mysqli; |
101 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
101 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
102 | if (is_null($li)) throw new Exception("Cannot execute mysql_errno(). No valid connection to server."); |
102 | if (is_null($li)) throw new Exception("Cannot execute mysql_errno(). No valid connection to server."); |
103 | 103 | ||
104 | return !empty($li->connect_errno) ? $li->connect_errno : $li->errno; |
104 | return !empty($li->connect_errno) ? $li->connect_errno : $li->errno; |
105 | } |
105 | } |
106 | 106 | ||
107 | // Liefert den Fehlertext der zuvor ausgeführten MySQL Operation |
107 | // Liefert den Fehlertext der zuvor ausgeführten MySQL Operation |
108 | function mysql_error($link_identifier=NULL) { |
108 | function mysql_error($link_identifier=NULL) { |
109 | global $vts_mysqli; |
109 | global $vts_mysqli; |
110 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
110 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
111 | if (is_null($li)) throw new Exception("Cannot execute mysql_error(). No valid connection to server."); |
111 | if (is_null($li)) throw new Exception("Cannot execute mysql_error(). No valid connection to server."); |
112 | 112 | ||
113 | return !empty($li->connect_error) ? $li->connect_error : $li->error; |
113 | return !empty($li->connect_error) ? $li->connect_error : $li->error; |
114 | } |
114 | } |
115 | 115 | ||
116 | // Maskiert einen String zur Benutzung in einer MySQL Abfrage |
116 | // Maskiert einen String zur Benutzung in einer MySQL Abfrage |
117 | function mysql_escape_string($unescaped_string) { |
117 | function mysql_escape_string($unescaped_string) { |
118 | global $vts_mysqli; |
118 | global $vts_mysqli; |
119 | return $vts_mysqli->real_escape_string($unescaped_string); |
119 | return $vts_mysqli->real_escape_string($unescaped_string); |
120 | } |
120 | } |
121 | 121 | ||
122 | // Liefert einen Datensatz als assoziatives Array, als numerisches Array oder beides |
122 | // Liefert einen Datensatz als assoziatives Array, als numerisches Array oder beides |
123 | define('MYSQL_ASSOC', MYSQLI_ASSOC); |
123 | define('MYSQL_ASSOC', MYSQLI_ASSOC); |
124 | define('MYSQL_NUM', MYSQLI_NUM); |
124 | define('MYSQL_NUM', MYSQLI_NUM); |
125 | define('MYSQL_BOTH', MYSQLI_BOTH); |
125 | define('MYSQL_BOTH', MYSQLI_BOTH); |
126 | function mysql_fetch_array($result, $result_type=MYSQL_BOTH) { |
126 | function mysql_fetch_array($result, $result_type=MYSQL_BOTH) { |
127 | if (!$result) { |
127 | if (!$result) { |
128 | $err = mysql_error(); |
128 | $err = mysql_error(); |
129 | throw new Exception("Called mysql_fetch_array() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
129 | throw new Exception("Called mysql_fetch_array() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
130 | } |
130 | } |
131 | return $result->fetch_array($result_type); |
131 | return $result->fetch_array($result_type); |
132 | } |
132 | } |
133 | 133 | ||
134 | // Liefert einen Datensatz als assoziatives Array |
134 | // Liefert einen Datensatz als assoziatives Array |
135 | function mysql_fetch_assoc($result) { |
135 | function mysql_fetch_assoc($result) { |
136 | if (!$result) { |
136 | if (!$result) { |
137 | $err = mysql_error(); |
137 | $err = mysql_error(); |
138 | throw new Exception("Called mysql_fetch_assoc() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
138 | throw new Exception("Called mysql_fetch_assoc() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
139 | } |
139 | } |
140 | return $result->fetch_assoc(); |
140 | return $result->fetch_assoc(); |
141 | } |
141 | } |
142 | 142 | ||
143 | // Liefert ein Objekt mit Feldinformationen aus einem Anfrageergebnis |
143 | // Liefert ein Objekt mit Feldinformationen aus einem Anfrageergebnis |
144 | function mysql_fetch_field($result, $field_offset=0) { |
144 | function mysql_fetch_field($result, $field_offset=0) { |
145 | if (!$result) { |
145 | if (!$result) { |
146 | $err = mysql_error(); |
146 | $err = mysql_error(); |
147 | throw new Exception("Called mysql_fetch_field() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
147 | throw new Exception("Called mysql_fetch_field() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
148 | } |
148 | } |
149 | return $result->fetch_field(); |
149 | return $result->fetch_field(); |
150 | } |
150 | } |
151 | 151 | ||
152 | // Liefert die Länge eines jeden Feldes in einem Ergebnis |
152 | // Liefert die Länge eines jeden Feldes in einem Ergebnis |
153 | function mysql_fetch_lengths($result) { |
153 | function mysql_fetch_lengths($result) { |
154 | if (!$result) { |
154 | if (!$result) { |
155 | $err = mysql_error(); |
155 | $err = mysql_error(); |
156 | throw new Exception("Called mysql_fetch_lengths() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
156 | throw new Exception("Called mysql_fetch_lengths() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
157 | } |
157 | } |
158 | return $result->lengths; |
158 | return $result->lengths; |
159 | } |
159 | } |
160 | 160 | ||
161 | // Liefert eine Ergebniszeile als Objekt |
161 | // Liefert eine Ergebniszeile als Objekt |
162 | function mysql_fetch_object($result, $class_name="stdClass", $params=null) { |
162 | function mysql_fetch_object($result, $class_name="stdClass", $params=null) { |
163 | if (!$result) { |
163 | if (!$result) { |
164 | $err = mysql_error(); |
164 | $err = mysql_error(); |
165 | throw new Exception("Called mysql_fetch_object() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
165 | throw new Exception("Called mysql_fetch_object() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
166 | } |
166 | } |
167 | if ($params) { |
167 | if ($params) { |
168 | return $result->fetch_object($class_name, $params); |
168 | return $result->fetch_object($class_name, $params); |
169 | } else { |
169 | } else { |
170 | return $result->fetch_object($class_name); |
170 | return $result->fetch_object($class_name); |
171 | } |
171 | } |
172 | } |
172 | } |
173 | 173 | ||
174 | // Liefert einen Datensatz als indiziertes Array |
174 | // Liefert einen Datensatz als indiziertes Array |
175 | function mysql_fetch_row($result) { |
175 | function mysql_fetch_row($result) { |
176 | if (!$result) { |
176 | if (!$result) { |
177 | $err = mysql_error(); |
177 | $err = mysql_error(); |
178 | throw new Exception("Called mysql_fetch_row() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
178 | throw new Exception("Called mysql_fetch_row() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
179 | } |
179 | } |
180 | return $result->fetch_row(); |
180 | return $result->fetch_row(); |
181 | } |
181 | } |
182 | 182 | ||
183 | // Liefert die Flags des spezifizierten Feldes in einem Anfrageergebnis |
183 | // Liefert die Flags des spezifizierten Feldes in einem Anfrageergebnis |
184 | function mysql_field_flags($result, $field_offset) { |
184 | function mysql_field_flags($result, $field_offset) { |
185 | if (!$result) { |
185 | if (!$result) { |
186 | $err = mysql_error(); |
186 | $err = mysql_error(); |
187 | throw new Exception("Called mysql_field_flags() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
187 | throw new Exception("Called mysql_field_flags() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
188 | } |
188 | } |
189 | return $result->fetch_field_direct($field_offset)->flags; |
189 | return $result->fetch_field_direct($field_offset)->flags; |
190 | } |
190 | } |
191 | 191 | ||
192 | // Liefert die Länge des angegebenen Feldes |
192 | // Liefert die Länge des angegebenen Feldes |
193 | function mysql_field_len($result, $field_offset) { |
193 | function mysql_field_len($result, $field_offset) { |
194 | if (!$result) { |
194 | if (!$result) { |
195 | $err = mysql_error(); |
195 | $err = mysql_error(); |
196 | throw new Exception("Called mysql_field_len() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
196 | throw new Exception("Called mysql_field_len() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
197 | } |
197 | } |
198 | return $result->fetch_field_direct($field_offset)->length; |
198 | return $result->fetch_field_direct($field_offset)->length; |
199 | } |
199 | } |
200 | 200 | ||
201 | // Liefert den Namen eines Feldes in einem Ergebnis |
201 | // Liefert den Namen eines Feldes in einem Ergebnis |
202 | function mysql_field_name($result, $field_offset) { |
202 | function mysql_field_name($result, $field_offset) { |
203 | if (!$result) { |
203 | if (!$result) { |
204 | $err = mysql_error(); |
204 | $err = mysql_error(); |
205 | throw new Exception("Called mysql_field_name() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
205 | throw new Exception("Called mysql_field_name() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
206 | } |
206 | } |
207 | return $result->fetch_field_direct()->name; //or "orgname" |
207 | return $result->fetch_field_direct($field_offset)->name; //or "orgname" |
208 | } |
208 | } |
209 | 209 | ||
210 | // Setzt den Ergebniszeiger auf ein bestimmtes Feldoffset |
210 | // Setzt den Ergebniszeiger auf ein bestimmtes Feldoffset |
211 | function mysql_field_seek($result, $field_offset) { |
211 | function mysql_field_seek($result, $field_offset) { |
212 | if (!$result) { |
212 | if (!$result) { |
213 | $err = mysql_error(); |
213 | $err = mysql_error(); |
214 | throw new Exception("Called mysql_field_seek() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
214 | throw new Exception("Called mysql_field_seek() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
215 | } |
215 | } |
216 | return $result->field_seek($field_offset); |
216 | return $result->field_seek($field_offset); |
217 | } |
217 | } |
218 | 218 | ||
219 | // Liefert den Namen der Tabelle, die das genannte Feld enthält |
219 | // Liefert den Namen der Tabelle, die das genannte Feld enthält |
220 | function mysql_field_table($result, $field_offset) { |
220 | function mysql_field_table($result, $field_offset) { |
221 | if (!$result) { |
221 | if (!$result) { |
222 | $err = mysql_error(); |
222 | $err = mysql_error(); |
223 | throw new Exception("Called mysql_field_table() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
223 | throw new Exception("Called mysql_field_table() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
224 | } |
224 | } |
225 | return $result->fetch_field_direct($field_offset)->table; // or "orgtable" |
225 | return $result->fetch_field_direct($field_offset)->table; // or "orgtable" |
226 | } |
226 | } |
227 | 227 | ||
228 | // Liefert den Typ des spezifizierten Feldes in einem Ergebnis |
228 | // Liefert den Typ des spezifizierten Feldes in einem Ergebnis |
229 | function mysql_field_type($result, $field_offset) { |
229 | function mysql_field_type($result, $field_offset) { |
230 | if (!$result) { |
230 | if (!$result) { |
231 | $err = mysql_error(); |
231 | $err = mysql_error(); |
232 | throw new Exception("Called mysql_field_type() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
232 | throw new Exception("Called mysql_field_type() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
233 | } |
233 | } |
234 | return $result->fetch_field_direct($field_offset)->type; |
234 | return $result->fetch_field_direct($field_offset)->type; |
235 | } |
235 | } |
236 | 236 | ||
237 | // Gibt belegten Speicher wieder frei |
237 | // Gibt belegten Speicher wieder frei |
238 | function mysql_free_result($result) { |
238 | function mysql_free_result($result) { |
239 | if (!$result) { |
239 | if (!$result) { |
240 | $err = mysql_error(); |
240 | $err = mysql_error(); |
241 | throw new Exception("Called mysql_free_result() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
241 | throw new Exception("Called mysql_free_result() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
242 | } |
242 | } |
243 | return $result->free(); |
243 | return $result->free(); |
244 | } |
244 | } |
245 | 245 | ||
246 | // Liefert MySQL Clientinformationen |
246 | // Liefert MySQL Clientinformationen |
247 | function mysql_get_client_info() { |
247 | function mysql_get_client_info() { |
248 | global $vts_mysqli; |
248 | global $vts_mysqli; |
249 | return $vts_mysqli->get_client_info(); |
249 | return $vts_mysqli->get_client_info(); |
250 | } |
250 | } |
251 | 251 | ||
252 | // Liefert MySQL Host Informationen |
252 | // Liefert MySQL Host Informationen |
253 | function mysql_get_host_info($link_identifier=NULL) { |
253 | function mysql_get_host_info($link_identifier=NULL) { |
254 | global $vts_mysqli; |
254 | global $vts_mysqli; |
255 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
255 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
256 | if (is_null($li)) throw new Exception("Cannot execute mysql_get_host_info(). No valid connection to server."); |
256 | if (is_null($li)) throw new Exception("Cannot execute mysql_get_host_info(). No valid connection to server."); |
257 | 257 | ||
258 | return $li->host_info; |
258 | return $li->host_info; |
259 | } |
259 | } |
260 | 260 | ||
261 | // Liefert MySQL Protokollinformationen |
261 | // Liefert MySQL Protokollinformationen |
262 | function mysql_get_proto_info($link_identifier=NULL) { |
262 | function mysql_get_proto_info($link_identifier=NULL) { |
263 | global $vts_mysqli; |
263 | global $vts_mysqli; |
264 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
264 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
265 | if (is_null($li)) throw new Exception("Cannot execute mysql_get_proto_info(). No valid connection to server."); |
265 | if (is_null($li)) throw new Exception("Cannot execute mysql_get_proto_info(). No valid connection to server."); |
266 | 266 | ||
267 | return $li->protocol_version; |
267 | return $li->protocol_version; |
268 | } |
268 | } |
269 | 269 | ||
270 | // Liefert MySQL Server Informationen |
270 | // Liefert MySQL Server Informationen |
271 | function mysql_get_server_info($link_identifier=NULL) { |
271 | function mysql_get_server_info($link_identifier=NULL) { |
272 | global $vts_mysqli; |
272 | global $vts_mysqli; |
273 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
273 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
274 | if (is_null($li)) throw new Exception("Cannot execute mysql_get_server_info(). No valid connection to server."); |
274 | if (is_null($li)) throw new Exception("Cannot execute mysql_get_server_info(). No valid connection to server."); |
275 | 275 | ||
276 | return $li->server_info; |
276 | return $li->server_info; |
277 | } |
277 | } |
278 | 278 | ||
279 | // Liefert Informationen über die zuletzt ausgeführte Anfrage zurück |
279 | // Liefert Informationen über die zuletzt ausgeführte Anfrage zurück |
280 | function mysql_info($link_identifier=NULL) { |
280 | function mysql_info($link_identifier=NULL) { |
281 | global $vts_mysqli; |
281 | global $vts_mysqli; |
282 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
282 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
283 | if (is_null($li)) throw new Exception("Cannot execute mysql_info(). No valid connection to server."); |
283 | if (is_null($li)) throw new Exception("Cannot execute mysql_info(). No valid connection to server."); |
284 | 284 | ||
285 | return $li->info; |
285 | return $li->info; |
286 | } |
286 | } |
287 | 287 | ||
288 | // Liefert die ID, die in der vorherigen Abfrage erzeugt wurde |
288 | // Liefert die ID, die in der vorherigen Abfrage erzeugt wurde |
289 | function mysql_insert_id($link_identifier=NULL) { |
289 | function mysql_insert_id($link_identifier=NULL) { |
290 | global $vts_mysqli; |
290 | global $vts_mysqli; |
291 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
291 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
292 | if (is_null($li)) throw new Exception("Cannot execute mysql_insert_id(). No valid connection to server."); |
292 | if (is_null($li)) throw new Exception("Cannot execute mysql_insert_id(). No valid connection to server."); |
293 | 293 | ||
294 | return $li->insert_id; |
294 | return $li->insert_id; |
295 | } |
295 | } |
296 | 296 | ||
297 | // Auflistung der verfügbaren Datenbanken (Schemata) auf einem MySQL Server |
297 | // Auflistung der verfügbaren Datenbanken (Schemata) auf einem MySQL Server |
298 | function mysql_list_dbs($link_identifier=NULL) { |
298 | function mysql_list_dbs($link_identifier=NULL) { |
299 | global $vts_mysqli; |
299 | global $vts_mysqli; |
300 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
300 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
301 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_dbs(). No valid connection to server."); |
301 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_dbs(). No valid connection to server."); |
302 | 302 | ||
303 | return mysql_query('SHOW DATABASES', $li); |
303 | return mysql_query('SHOW DATABASES', $li); |
304 | } |
304 | } |
305 | 305 | ||
306 | // Listet MySQL Tabellenfelder auf |
306 | // Listet MySQL Tabellenfelder auf |
307 | function mysql_list_fields($database_name, $table_name, $link_identifier=NULL) { |
307 | function mysql_list_fields($database_name, $table_name, $link_identifier=NULL) { |
308 | global $vts_mysqli; |
308 | global $vts_mysqli; |
309 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
309 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
310 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_fields(). No valid connection to server."); |
310 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_fields(). No valid connection to server."); |
311 | 311 | ||
312 | return mysql_query("SHOW COLUMNS FROM `$database_name`.`$table_name`", $li); |
312 | return mysql_query("SHOW COLUMNS FROM `$database_name`.`$table_name`", $li); |
313 | } |
313 | } |
314 | 314 | ||
315 | // Zeigt die MySQL Prozesse an |
315 | // Zeigt die MySQL Prozesse an |
316 | function mysql_list_processes($link_identifier=NULL) { |
316 | function mysql_list_processes($link_identifier=NULL) { |
317 | global $vts_mysqli; |
317 | global $vts_mysqli; |
318 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
318 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
319 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_processes(). No valid connection to server."); |
319 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_processes(). No valid connection to server."); |
320 | 320 | ||
321 | return $li->thread_id; |
321 | return $li->thread_id; |
322 | } |
322 | } |
323 | 323 | ||
324 | // Listet Tabellen in einer MySQL Datenbank auf |
324 | // Listet Tabellen in einer MySQL Datenbank auf |
325 | function mysql_list_tables($database, $link_identifier=NULL) { |
325 | function mysql_list_tables($database, $link_identifier=NULL) { |
326 | global $vts_mysqli; |
326 | global $vts_mysqli; |
327 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
327 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
328 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_tables(). No valid connection to server."); |
328 | if (is_null($li)) throw new Exception("Cannot execute mysql_list_tables(). No valid connection to server."); |
329 | 329 | ||
330 | return mysql_query("SHOW TABLES FROM `$database`", $li); |
330 | return mysql_query("SHOW TABLES FROM `$database`", $li); |
331 | } |
331 | } |
332 | 332 | ||
333 | // Liefert die Anzahl der Felder in einem Ergebnis |
333 | // Liefert die Anzahl der Felder in einem Ergebnis |
334 | function mysql_num_fields($result) { |
334 | function mysql_num_fields($result) { |
335 | if (!$result) { |
335 | if (!$result) { |
336 | $err = mysql_error(); |
336 | $err = mysql_error(); |
337 | throw new Exception("Called mysql_num_fields() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
337 | throw new Exception("Called mysql_num_fields() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
338 | } |
338 | } |
339 | global $vts_mysqli; |
339 | global $vts_mysqli; |
340 | return $vts_mysqli->field_count; |
340 | return $vts_mysqli->field_count; |
341 | } |
341 | } |
342 | 342 | ||
343 | // Liefert die Anzahl der Zeilen im Ergebnis |
343 | // Liefert die Anzahl der Zeilen im Ergebnis |
344 | function mysql_num_rows($result) { |
344 | function mysql_num_rows($result) { |
345 | if (!$result) { |
345 | if (!$result) { |
346 | $err = mysql_error(); |
346 | $err = mysql_error(); |
347 | throw new Exception("Called mysql_num_rows() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
347 | throw new Exception("Called mysql_num_rows() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
348 | } |
348 | } |
349 | return $result->num_rows; |
349 | return $result->num_rows; |
350 | } |
350 | } |
351 | 351 | ||
352 | // Öffnet eine persistente Verbindung zum MySQL Server |
352 | // Öffnet eine persistente Verbindung zum MySQL Server |
353 | function mysql_pconnect($server=null, $username=null, $password=null, $client_flags=0) { |
353 | function mysql_pconnect($server=null, $username=null, $password=null, $client_flags=0) { |
354 | global $vts_mysqli; |
354 | global $vts_mysqli; |
355 | $ary = explode(':', $server); |
355 | $ary = explode(':', $server); |
356 | $host = $ary[0]; |
356 | $host = $ary[0]; |
357 | $ini_port = ini_get("mysqli.default_port"); |
357 | $ini_port = ini_get("mysqli.default_port"); |
358 | $port = isset($ary[1]) ? (int)$ary[1] : ($ini_port ? (int)$ini_port : 3306); |
358 | $port = isset($ary[1]) ? (int)$ary[1] : ($ini_port ? (int)$ini_port : 3306); |
359 | if (is_null($server)) $port = ini_get("mysqli.default_host"); |
359 | if (is_null($server)) $port = ini_get("mysqli.default_host"); |
360 | if (is_null($username)) $port = ini_get("mysqli.default_user"); |
360 | if (is_null($username)) $port = ini_get("mysqli.default_user"); |
361 | if (is_null($password)) $port = ini_get("mysqli.default_password"); |
361 | if (is_null($password)) $port = ini_get("mysqli.default_password"); |
362 | $vts_mysqli = new mysqli('p:'.$host, $username, $password, /*dbname*/'', $port, ini_get("mysqli.default_socket")); |
362 | $vts_mysqli = new mysqli('p:'.$host, $username, $password, /*dbname*/'', $port, ini_get("mysqli.default_socket")); |
363 | return (empty($vts_mysqli->connect_error) && ($vts_mysqli->connect_errno == 0)) ? $vts_mysqli : false; |
363 | return (empty($vts_mysqli->connect_error) && ($vts_mysqli->connect_errno == 0)) ? $vts_mysqli : false; |
364 | } |
364 | } |
365 | 365 | ||
366 | // Ping a server connection or reconnect if there is no connection |
366 | // Ping a server connection or reconnect if there is no connection |
367 | function mysql_ping($link_identifier=NULL) { |
367 | function mysql_ping($link_identifier=NULL) { |
368 | global $vts_mysqli; |
368 | global $vts_mysqli; |
369 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
369 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
370 | if (is_null($li)) throw new Exception("Cannot execute mysql_ping(). No valid connection to server."); |
370 | if (is_null($li)) throw new Exception("Cannot execute mysql_ping(). No valid connection to server."); |
371 | 371 | ||
372 | return $li->ping(); |
372 | return $li->ping(); |
373 | } |
373 | } |
374 | 374 | ||
375 | // Sendet eine Anfrage an MySQL |
375 | // Sendet eine Anfrage an MySQL |
376 | function mysql_query($query, $link_identifier=NULL) { |
376 | function mysql_query($query, $link_identifier=NULL) { |
377 | global $vts_mysqli; |
377 | global $vts_mysqli; |
378 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
378 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
379 | if (is_null($li)) throw new Exception("Cannot execute mysql_query(). No valid connection to server."); |
379 | if (is_null($li)) throw new Exception("Cannot execute mysql_query(). No valid connection to server."); |
380 | 380 | ||
381 | return $li->query($query, $resultmode=MYSQLI_STORE_RESULT); |
381 | return $li->query($query, $resultmode=MYSQLI_STORE_RESULT); |
382 | } |
382 | } |
383 | 383 | ||
384 | // Maskiert spezielle Zeichen innerhalb eines Strings für die Verwendung in einer SQL-Anweisung |
384 | // Maskiert spezielle Zeichen innerhalb eines Strings für die Verwendung in einer SQL-Anweisung |
385 | function mysql_real_escape_string($unescaped_string, $link_identifier=NULL) { |
385 | function mysql_real_escape_string($unescaped_string, $link_identifier=NULL) { |
386 | global $vts_mysqli; |
386 | global $vts_mysqli; |
387 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
387 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
388 | if (is_null($li)) throw new Exception("Cannot execute mysql_real_escape_string(). No valid connection to server."); |
388 | if (is_null($li)) throw new Exception("Cannot execute mysql_real_escape_string(). No valid connection to server."); |
389 | 389 | ||
390 | return $li->escape_string($unescaped_string); |
390 | return $li->escape_string($unescaped_string); |
391 | } |
391 | } |
392 | 392 | ||
393 | // Liefert Ergebnis |
393 | // Liefert Ergebnis |
394 | function mysql_result($result, $row, $field=0) { |
394 | function mysql_result($result, $row, $field=0) { |
395 | if (!$result) { |
395 | if (!$result) { |
396 | $err = mysql_error(); |
396 | $err = mysql_error(); |
397 | throw new Exception("Called mysql_result() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
397 | throw new Exception("Called mysql_result() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
398 | } |
398 | } |
399 | $result->data_seek($row); |
399 | $result->data_seek($row); |
400 | return mysql_fetch_array($result)[$field]; |
400 | return mysql_fetch_array($result)[$field]; |
401 | } |
401 | } |
402 | 402 | ||
403 | // Auswahl einer MySQL Datenbank |
403 | // Auswahl einer MySQL Datenbank |
404 | function mysql_select_db($database_name, $link_identifier=NULL) { |
404 | function mysql_select_db($database_name, $link_identifier=NULL) { |
405 | global $vts_mysqli; |
405 | global $vts_mysqli; |
406 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
406 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
407 | if (is_null($li)) throw new Exception("Cannot execute mysql_select_db(). No valid connection to server."); |
407 | if (is_null($li)) throw new Exception("Cannot execute mysql_select_db(). No valid connection to server."); |
408 | 408 | ||
409 | return $li->select_db($database_name); |
409 | return $li->select_db($database_name); |
410 | } |
410 | } |
411 | 411 | ||
412 | // Setzt den Verbindungszeichensatz |
412 | // Setzt den Verbindungszeichensatz |
413 | function mysql_set_charset($charset, $link_identifier=NULL) { |
413 | function mysql_set_charset($charset, $link_identifier=NULL) { |
414 | global $vts_mysqli; |
414 | global $vts_mysqli; |
415 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
415 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
416 | if (is_null($li)) throw new Exception("Cannot execute mysql_set_charset(). No valid connection to server."); |
416 | if (is_null($li)) throw new Exception("Cannot execute mysql_set_charset(). No valid connection to server."); |
417 | 417 | ||
418 | return $li->set_charset($charset); |
418 | return $li->set_charset($charset); |
419 | } |
419 | } |
420 | 420 | ||
421 | // Zeigt den momentanen Serverstatus an |
421 | // Zeigt den momentanen Serverstatus an |
422 | function mysql_stat($link_identifier=NULL) { |
422 | function mysql_stat($link_identifier=NULL) { |
423 | global $vts_mysqli; |
423 | global $vts_mysqli; |
424 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
424 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
425 | if (is_null($li)) throw new Exception("Cannot execute mysql_stat(). No valid connection to server."); |
425 | if (is_null($li)) throw new Exception("Cannot execute mysql_stat(). No valid connection to server."); |
426 | 426 | ||
427 | return $li->stat(); |
427 | return $li->stat(); |
428 | } |
428 | } |
429 | 429 | ||
430 | // Liefert den Namen einer Tabelle |
430 | // Liefert den Namen einer Tabelle |
431 | function mysql_tablename($result, $i) { |
431 | function mysql_tablename($result, $i) { |
432 | if (!$result) { |
432 | if (!$result) { |
433 | $err = mysql_error(); |
433 | $err = mysql_error(); |
434 | throw new Exception("Called mysql_tablename() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
434 | throw new Exception("Called mysql_tablename() with an erroneous argument.".($err == '' ? '' : " Possible cause: $err")); |
435 | } |
435 | } |
436 | $result->data_seek($i); |
436 | $result->data_seek($i); |
437 | return mysql_fetch_array($result)[0]; |
437 | return mysql_fetch_array($result)[0]; |
438 | } |
438 | } |
439 | 439 | ||
440 | // Zeigt die aktuelle Thread ID an |
440 | // Zeigt die aktuelle Thread ID an |
441 | function mysql_thread_id($link_identifier=NULL) { |
441 | function mysql_thread_id($link_identifier=NULL) { |
442 | global $vts_mysqli; |
442 | global $vts_mysqli; |
443 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
443 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
444 | if (is_null($li)) throw new Exception("Cannot execute mysql_thread_id(). No valid connection to server."); |
444 | if (is_null($li)) throw new Exception("Cannot execute mysql_thread_id(). No valid connection to server."); |
445 | 445 | ||
446 | return $li->thread_id; |
446 | return $li->thread_id; |
447 | } |
447 | } |
448 | 448 | ||
449 | // Sendet eine SQL Anfrage an MySQL, ohne Ergebniszeilen abzuholen und zu puffern |
449 | // Sendet eine SQL Anfrage an MySQL, ohne Ergebniszeilen abzuholen und zu puffern |
450 | function mysql_unbuffered_query($query, $link_identifier=NULL) { |
450 | function mysql_unbuffered_query($query, $link_identifier=NULL) { |
451 | global $vts_mysqli; |
451 | global $vts_mysqli; |
452 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
452 | $li = is_null($link_identifier) ? $vts_mysqli : $link_identifier; |
453 | if (is_null($li)) throw new Exception("Cannot execute mysql_unbuffered_query(). No valid connection to server."); |
453 | if (is_null($li)) throw new Exception("Cannot execute mysql_unbuffered_query(). No valid connection to server."); |
454 | 454 | ||
455 | // http://php.net/manual/de/mysqlinfo.concepts.buffering.php |
455 | // http://php.net/manual/de/mysqlinfo.concepts.buffering.php |
456 | // https://stackoverflow.com/questions/1982016/unbuffered-query-with-mysqli?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
456 | // https://stackoverflow.com/questions/1982016/unbuffered-query-with-mysqli?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa |
457 | $li->real_query($query); |
457 | $li->real_query($query); |
458 | $li->use_result(); |
458 | $li->use_result(); |
459 | } |
459 | } |
460 | 460 | ||
461 | 461 |