├── LICENSE ├── README.md ├── composer.json └── fix_mysql.inc.php /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-mysql-fix 2 | 3 | A replacement for all mysql functions with mysqli equivalents. 4 | 5 | Be aware, that this is just a workaround to fix-up some old code and the resulting project 6 | will be more vulnerable than if you use the recommended newer mysqli-functions instead. 7 | So only If you are sure that this is not setting your server at risk, you can fix your old 8 | code by adding this replacement. 9 | 10 | ### usage 11 | 12 | You can install it via Composer adding this to your `composer.json`: 13 | 14 | ```json 15 | { 16 | "require": { 17 | "rubo77/php-mysql-fix": "^4.0" 18 | }, 19 | "autoload": { 20 | "files": [ 21 | "vendor/rubo77/php-mysql-fix/fix_mysql.inc.php" 22 | ] 23 | } 24 | } 25 | 26 | ``` 27 | 28 | and then typing: 29 | 30 | ```sh 31 | $ composer update 32 | ``` 33 | 34 | Alternatively you can manually download and include the file at the top of your PHP script: 35 | 36 | ```php 37 | = 0){ 171 | mysqli_data_seek($result, $row); 172 | $resultrow = (is_numeric($col)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result); 173 | if (isset($resultrow[$col])){ 174 | return $resultrow[$col]; 175 | } 176 | } 177 | return false; 178 | } 179 | 180 | function mysql_escape_string($s, $link_identifier = null){ 181 | global $global_link_identifier; 182 | if($link_identifier == null) { 183 | $link_identifier = $global_link_identifier; 184 | } 185 | return mysqli_real_escape_string($link_identifier, $s); 186 | } 187 | 188 | function mysql_fetch_field($result, $i = null) { 189 | if ($i === null) { 190 | return mysqli_fetch_field($result); 191 | } 192 | return mysqli_fetch_field_direct($result, $i); 193 | } 194 | 195 | function mysql_field_name($result, $i) { 196 | return mysqli_fetch_field_direct($result, $i)->name; 197 | } 198 | 199 | function mysql_field_type($result, $i){ 200 | return mysqli_fetch_field_direct($result, $i)->type; 201 | } 202 | 203 | function mysql_field_len($result, $i){ 204 | return mysqli_fetch_field_direct($result, $i)->length; 205 | } 206 | 207 | function mysql_num_fields($result){ 208 | return mysqli_num_fields($result); 209 | } 210 | 211 | function mysql_free_result($result) { 212 | return is_bool($result) ? true : mysqli_free_result($result); 213 | } 214 | 215 | function mysql_get_server_info($link_identifier = null){ 216 | global $global_link_identifier; 217 | if($link_identifier == null) { 218 | $link_identifier = $global_link_identifier; 219 | } 220 | return mysqli_get_server_info($link_identifier); 221 | } 222 | 223 | function mysql_set_charset($csname, $link_identifier = null){ 224 | global $global_link_identifier; 225 | if($link_identifier == null) { 226 | $link_identifier = $global_link_identifier; 227 | } 228 | return mysqli_set_charset($link_identifier, $csname); 229 | } 230 | 231 | // aliases 232 | function mysql(...$args){ return mysql_db_query(...$args); } 233 | function mysql_createdb(...$args){ return mysql_create_db(...$args); } 234 | function mysql_db_name(...$args){ return mysql_result(...$args); } 235 | function mysql_dbname(...$args){ return mysql_result(...$args); } 236 | function mysql_dropdb(...$args){ return mysql_drop_db(...$args); } 237 | function mysql_fieldflags(...$args){ return mysql_field_flags(...$args); } 238 | function mysql_fieldlen(...$args){ return mysql_field_len(...$args); } 239 | function mysql_fieldname(...$args){ return mysql_field_name(...$args); } 240 | function mysql_fieldtable(...$args){ return mysql_field_table(...$args); } 241 | function mysql_fieldtype(...$args){ return mysql_field_type(...$args); } 242 | function mysql_freeresult(...$args){ return mysql_free_result(...$args); } 243 | function mysql_listdbs(...$args){ return mysql_list_dbs(...$args); } 244 | function mysql_listfields(...$args){ return mysql_list_fields(...$args); } 245 | function mysql_listtables(...$args){ return mysql_list_tables(...$args); } 246 | function mysql_numfields(...$args){ return mysql_num_fields(...$args); } 247 | function mysql_numrows(...$args){ return mysql_num_rows(...$args); } 248 | function mysql_selectdb(...$args){ return mysql_select_db(...$args); } 249 | 250 | // TODO: those functions are not defined yet: 251 | function mysql_client_encoding(){ trigger_error("mysql_client_encoding is not defined yet", E_USER_ERROR); } 252 | function mysql_create_db(){ trigger_error("mysql_create_db is not defined yet", E_USER_ERROR); } 253 | function mysql_drop_db(){ trigger_error("mysql_drop_db is not defined yet", E_USER_ERROR); } 254 | function mysql_fetch_lengths(){ trigger_error("mysql_fetch_lengths is not defined yet", E_USER_ERROR); } 255 | function mysql_field_flags(){ trigger_error("mysql_field_flags is not defined yet", E_USER_ERROR); } 256 | function mysql_field_seek(){ trigger_error("mysql_field_seek is not defined yet", E_USER_ERROR); } 257 | function mysql_field_table(){ trigger_error("mysql_field_table is not defined yet", E_USER_ERROR); } 258 | function mysql_get_client_info(){ trigger_error("mysql_get_client_info is not defined yet", E_USER_ERROR); } 259 | function mysql_get_host_info(){ trigger_error("mysql_get_host_info is not defined yet", E_USER_ERROR); } 260 | function mysql_get_proto_info(){ trigger_error("mysql_get_proto_info is not defined yet", E_USER_ERROR); } 261 | function mysql_info(){ trigger_error("mysql_info is not defined yet", E_USER_ERROR); } 262 | function mysql_list_dbs(){ trigger_error("mysql_list_dbs is not defined yet", E_USER_ERROR); } 263 | function mysql_list_fields(){ trigger_error("mysql_list_fields is not defined yet", E_USER_ERROR); } 264 | function mysql_list_processes(){ trigger_error("mysql_list_processes is not defined yet", E_USER_ERROR); } 265 | function mysql_tablename(){ trigger_error("mysql_tablename is not defined yet", E_USER_ERROR); } 266 | function mysql_stat(){ trigger_error("mysql_stat is not defined yet", E_USER_ERROR); } 267 | function mysql_thread_id(){ trigger_error("mysql_thread_id is not defined yet", E_USER_ERROR); } 268 | function mysql_unbuffered_query(){ trigger_error("mysql_unbuffered_query is not defined yet", E_USER_ERROR); } 269 | } 270 | --------------------------------------------------------------------------------