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