Giter Club home page Giter Club logo

php7-compat's Introduction

php7-compat

Wrapper functions around the deprecated mysql_* and ereg* functions for use in PHP 7

Usage

In php.ini, add the following line (adjust the path depending on where you put the compatibility library):

auto_prepend_file = "/usr/local/share/php7-compat/php7-compat.php"

Alternatively, use

include( '/usr/local/share/php7-compat/php7-compat.php' );

as required.

Notes

For use with large legacy codebases, where PHP needs to updated but rewriting the code is impractical. Includes wrappers for the most commonly used mysql_* functions, mapping them onto their closest mysqli_* counterpart. Also includes wrappers for the ereg* and split* functions, mapping them onto their preg_* equivalents.

Apache-licensed so you are free to use the code as you see fit, and we don't have to worry about software patents.

Use the code by cloning the repository, and then either via the auto_prepend_file option in php.ini (recommended), or loading it in individual files as required. The library can safely be loaded multiple times and in PHP 5 environments: it only generates the function definitions if they aren't already present.

Limitations:

  1. Doesn't always work reliably with codebases that have connections open to multiple databases within the same file. This is a fundamental limitation, as most of the mysql_* functions didn't require a database link as an argument, whereas many of the newer mysqli_* functions do. We store the most recently used database connection in a global variable, and default to using that if the link variable was not passed into the mysql_* function call.
  2. Not all functions have been redefined. Contributions welcome! Missing functions are:
  • mysql_client_encoding
  • mysql_create_db
  • mysql_db_name
  • mysql_fetch_lengths
  • mysql_field_flags
  • mysql_field_len
  • mysql_field_seek
  • mysql_field_table
  • mysql_get_client_info
  • mysql_get_host_info
  • mysql_get_proto_info
  • mysql_info
  • mysql_list_processes
  • mysql_list_tables
  • mysql_stat
  • mysql_tablename
  • mysql_thread_id
  • mysql_unbuffered_query

php7-compat's People

Contributors

dafuki avatar kitserve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dafuki kdkd

php7-compat's Issues

tagging a release

This repo appears to not have many changes ongoing. Any chance you'd tag a release?

Should this wrapper library include typehints?

Currently there are no typehints in the code. This maximises compatibility, but also increases the risk of bugs creeping in, for example as occurred in #11. Should we include typehints? Adding them in would make the code incompatible with PHP 5, but that's probably not such a big issue since it's intended to allow PHP 5 code to run in newer PHP versions. More problematic is that PHP's typehinting has changed between versions 7.x and 8.x. Even if we were to add in typehints, we'd probably be forced to stick with 7.0 syntax and avoid any of the more advanced union types.

Additionally/alternatively, we could just use docblock function declarations. This wouldn't provide any strict guarantees about function arguments and return types, but would at least encourage checking legacy mysql_* function signatures against the wrappers in this library.

mysql_close does not unset global link

This can lead to situations where the link seems like it was set up and causes other calls to fail. In one legacy application, for who knows what reason, they connected to the database to run a query, closed the connection, then immediately opened another connection. Due to above, this always fails with the first query/select DB on the second connection.

mysql_connect does not use a globally shared link

mysql_connect does not use a globally shared link.
I needed to switch some sites to mysql_pconnect.
Is there a reason for mysql_conect to not create a global $link var?
This does not replicate the mysql_connect behavior of older php versions, was wondering if it is on purpose.

mysql_numrows for php4 code

mysql_numrows (not num_rows) is still used in some very old code.
Maybe consider adding a wrapper to it, too?

ereg functions and split(i) should use addcslashes, not preg_quote

As it is now, preg_quote escapes regular expressions into normal strings, which won't work, of course. The fix is simply to replace all instances of preg_quote with addcslashes so that only slashes are escaped for preg_* functions. Function arguments remain the same.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.