Skip to content

Commit

Permalink
add wraper to databases; reorganize structure and add composer support
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Braz committed Nov 28, 2018
1 parent f4fc108 commit a8843c7
Show file tree
Hide file tree
Showing 6 changed files with 661 additions and 406 deletions.
17 changes: 17 additions & 0 deletions composer.json
@@ -0,0 +1,17 @@
{
"name": "fbraz3/php5-compatibility-layer",
"description": "Implementa de forma transparente funções que foram descontinuadas no PHP7",
"type": "library",
"license": "GPL-3.0",
"require": {
"php": "^7.0",
"ext-openssl": "*"
},
"autoload": {
"files": [
"src/wrapper-legacy.php",
"src/wrapper-mssql.php",
"src/wrapper-mysql.php"
]
}
}
19 changes: 19 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/mysql.php
@@ -0,0 +1,11 @@
<?php

if (!function_exists('mysql_connect')) {
echo "Function mysql_connect not exists!\n";
}

require_once __DIR__ . '/../vendor/autoload.php';

if (function_exists('mysql_connect')) {
echo "Function mysql_connect now exists!\n";
}
107 changes: 107 additions & 0 deletions src/wrapper-legacy.php
@@ -0,0 +1,107 @@
<?php
/**
* Created by PhpStorm.
* User: felipebraz
* Date: 09/07/18
* Time: 13:33
*/

if (!function_exists('ereg')) {
function ereg($pattern, $subject, &$matches = array())
{
return preg_match('/' . $pattern . '/', $subject, $matches);
}
}
if (!function_exists('eregi')) {
function eregi($pattern, $subject, &$matches = array())
{
return preg_match('/' . $pattern . '/i', $subject, $matches);
}
}
if (!function_exists('ereg_replace')) {
function ereg_replace($pattern, $replacement, $string)
{
return preg_replace('/' . $pattern . '/', $replacement, $string);
}
}
if (!function_exists('eregi_replace')) {
function eregi_replace($pattern, $replacement, $string)
{
return preg_replace('/' . $pattern . '/i', $replacement, $string);
}
}
if (!function_exists('split')) {
function split($pattern, $subject, $limit = -1)
{
return preg_split('/' . $pattern . '/', $subject, $limit);
}
}
if (!function_exists('spliti')) {
function spliti($pattern, $subject, $limit = -1)
{
return preg_split('/' . $pattern . '/i', $subject, $limit);
}
}
if (!function_exists('session_unregister')) {
function session_unregister($value)
{
unset($_SESSION[$value]);
return true;
}
}
if (!function_exists('session_register')) {
function session_register($variavel)
{
global $$variavel;
$_SESSION[$variavel] = $$variavel;
return true;
}
}

/**
* Escapa as mesmas strings do mysql_real_escape_string, mas sem precisar de ponteiro de conexao
* "Characters encoded are \, ', ", NUL (ASCII 0), \n, \r, and Control+Z"
* @see https://dev.mysql.com/doc/refman/5.7/en/mysql-real-escape-string.html
* @see https://stackoverflow.com/questions/1162491/alternative-to-mysql-real-escape-string-without-connecting-to-db
* @param string $value
* @return string
*/
function mres($value)
{
$search = array("\\", "\x00", "\n", "\r", "'", '"', "\x1a");
$replace = array("\\\\", "\\0", "\\n", "\\r", "\'", '\"', "\\Z");

return str_replace($search, $replace, $value);
}

if (!function_exists('mysql_real_escape_string')) {
/**
* Escapes special characters in a string for use in an SQL statement
* @link http://php.net/manual/en/function.mysql-real-escape-string.php
* The string that is to be escaped.
* </p>
* @return string the escaped string, or false on error.
* @since 4.3.0
* @since 5.0
*/
function mysql_real_escape_string($value)
{
return mres($value);
}
}
if (!function_exists('mysql_escape_string')) {
/**
* Escapes a string for use in a mysql_query
* @link http://php.net/manual/en/function.mysql-escape-string.php
* @deprecated 5.3.0 Use mysql_real_escape_string() instead
* The string that is to be escaped.
* </p>
* @return string the escaped string.
* @since 4.0.3
* @since 5.0
*/
function mysql_escape_string($value)
{
return mres($value);
}
}

0 comments on commit a8843c7

Please sign in to comment.