commit
546a74246d
|
@ -0,0 +1,22 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
|
@ -0,0 +1,215 @@
|
|||
#################
|
||||
## Eclipse
|
||||
#################
|
||||
|
||||
*.pydevproject
|
||||
.project
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.classpath
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
|
||||
#################
|
||||
## Visual Studio
|
||||
#################
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
build/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.log
|
||||
*.scc
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
*.pubxml
|
||||
|
||||
# NuGet Packages Directory
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||
#packages/
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.[Pp]ublish.xml
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
App_Data/*.mdf
|
||||
App_Data/*.ldf
|
||||
|
||||
#############
|
||||
## Windows detritus
|
||||
#############
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Mac crap
|
||||
.DS_Store
|
||||
|
||||
|
||||
#############
|
||||
## Python
|
||||
#############
|
||||
|
||||
*.py[co]
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist/
|
||||
build/
|
||||
eggs/
|
||||
parts/
|
||||
var/
|
||||
sdist/
|
||||
develop-eggs/
|
||||
.installed.cfg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
|
||||
#Translations
|
||||
*.mo
|
||||
|
||||
#Mr Developer
|
||||
.mr.developer.cfg
|
|
@ -0,0 +1,2 @@
|
|||
This is a Subversion working copy administrative directory.
|
||||
Visit http://subversion.tigris.org/ for more information.
|
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 58
|
||||
/svnpublic/mysqli_converter/!svn/ver/11/MySQLConverterTool
|
||||
END
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<wc-entries
|
||||
xmlns="svn:">
|
||||
<entry
|
||||
committed-rev="11"
|
||||
name=""
|
||||
committed-date="2006-09-28T08:12:53.940894Z"
|
||||
url="http://svn.mysql.com/svnpublic/mysqli_converter/MySQLConverterTool"
|
||||
last-author="uwendel"
|
||||
kind="dir"
|
||||
uuid="366cee77-c380-44c0-aa1c-990a1e0ff0dc"
|
||||
repos="http://svn.mysql.com/svnpublic/mysqli_converter"
|
||||
revision="11"/>
|
||||
<entry
|
||||
name="UnitTests"
|
||||
kind="dir"/>
|
||||
<entry
|
||||
name="GUI"
|
||||
kind="dir"/>
|
||||
<entry
|
||||
name="Function"
|
||||
kind="dir"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="Converter.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="9860d4470b2e329a2a11aa0fbd6e513c"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="README"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="145afcc6ffb9e625fd4a9fdcfc427d03"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="cli.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="f43e3acf8f019f618fe65f25f7848d05"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="index.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="f13f57f217c52733cee4051b00fb1c4e"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
</wc-entries>
|
|
@ -0,0 +1 @@
|
|||
4
|
|
@ -0,0 +1,936 @@
|
|||
<?PHP
|
||||
require_once('Function/ChangeUser.php');
|
||||
require_once('Function/Connect.php');
|
||||
require_once('Function/ConnParam.php');
|
||||
require_once('Function/ConnParamBool.php');
|
||||
require_once('Function/CreateDB.php');
|
||||
require_once('Function/DBQuery.php');
|
||||
require_once('Function/DropDB.php');
|
||||
require_once('Function/Error.php');
|
||||
require_once('Function/EscapeString.php');
|
||||
require_once('Function/FetchField.php');
|
||||
require_once('Function/FieldFlags.php');
|
||||
require_once('Function/FieldLen.php');
|
||||
require_once('Function/FieldName.php');
|
||||
require_once('Function/FieldTable.php');
|
||||
require_once('Function/FieldType.php');
|
||||
require_once('Function/FreeResult.php');
|
||||
require_once('Function/Generic.php');
|
||||
require_once('Function/GenericBoolean.php');
|
||||
require_once('Function/ListDBs.php');
|
||||
require_once('Function/ListFields.php');
|
||||
require_once('Function/ListProcesses.php');
|
||||
require_once('Function/ListTables.php');
|
||||
require_once('Function/ParReversed.php');
|
||||
require_once('Function/RealEscapeString.php');
|
||||
require_once('Function/SelectDB.php');
|
||||
require_once('Function/Tablename.php');
|
||||
require_once('Function/UnbufferedQuery.php');
|
||||
|
||||
/**
|
||||
* ext/mysql->ext/mysqli Converter
|
||||
*
|
||||
* @category Converter
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Converter {
|
||||
|
||||
//
|
||||
// protected
|
||||
//
|
||||
|
||||
/**
|
||||
* Scanner state constant
|
||||
*
|
||||
* @const
|
||||
* @access protected
|
||||
*/
|
||||
const STATE_NORMAL = 'normal_state';
|
||||
|
||||
|
||||
/**
|
||||
* Scanner state constant
|
||||
*
|
||||
* @const
|
||||
* @access protectd
|
||||
*/
|
||||
const STATE_FUNC_FOUND = 'func_found';
|
||||
|
||||
|
||||
/**
|
||||
* Scanner state constant
|
||||
*
|
||||
* @const
|
||||
* @access protected
|
||||
*/
|
||||
const STATE_PARAM_LIST = 'parameter_list';
|
||||
|
||||
|
||||
/**
|
||||
* Converted (= resulting) source code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $output = '';
|
||||
|
||||
|
||||
/**
|
||||
* List of errors which occured during the conversion
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
|
||||
/**
|
||||
* List of PHP token
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tokens = array();
|
||||
|
||||
|
||||
/**
|
||||
* Mapping of ext/mysql -> ext/mysqli constants
|
||||
*
|
||||
*/
|
||||
protected $mysql_ext_consts = array(
|
||||
'MYSQL_CLIENT_COMPRESS' => 'MYSQLI_CLIENT_COMPRESS',
|
||||
'MYSQL_CLIENT_IGNORE_SPACE' => 'MYSQLI_CLIENT_IGNORE_SPACE',
|
||||
'MYSQL_CLIENT_INTERACTIVE' => 'MYSQLI_CLIENT_INTERACTIVE',
|
||||
'MYSQL_CLIENT_SSL' => 'MYSQLI_CLIENT_SSL',
|
||||
'MYSQL_ASSOC' => 'MYSQLI_ASSOC',
|
||||
'MYSQL_BOTH' => 'MYSQLI_BOTH',
|
||||
'MYSQL_NUM' => 'MYSQLI_NUM',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Number of functions found in the given source
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $funcs_found = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Number of functions converted in the given source
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $funcs_converted = 0;
|
||||
|
||||
|
||||
/**
|
||||
* List of functions that are not supported
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mysql_funcs_not_supported = array(
|
||||
// rewrite the ugly mysql_result calls manually!
|
||||
'mysql_result' => true,
|
||||
// whatever that function is...
|
||||
'mysql_fetch_field2' => true,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* List of functions that can be converted
|
||||
*
|
||||
* Acts as kind of a function pointer list, but with objects
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mysql_funcs = array();
|
||||
|
||||
|
||||
/**
|
||||
* Flag: enable token debug output?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug_dump_tokens = false;
|
||||
|
||||
|
||||
/**
|
||||
* Flag: enable parameter parsing debug output?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug_dump_params = false;
|
||||
|
||||
|
||||
/**
|
||||
* Current line number during the parsing process
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineno = 0;
|
||||
|
||||
|
||||
//
|
||||
// public
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param bool Turn on debug output of scanner token?
|
||||
* @param bool Turn on debug output of function parameters?
|
||||
*/
|
||||
public function __construct($debug_token = false, $debug_params = false) {
|
||||
|
||||
if (!function_exists('token_name')) {
|
||||
// HACK FIXME
|
||||
die('ext/tokenizer is needed!\n');
|
||||
}
|
||||
|
||||
if (!defined('T_ML_COMMENT'))
|
||||
define('T_ML_COMMENT', T_COMMENT);
|
||||
|
||||
if (!defined('T_DOC_COMMENT'))
|
||||
define('T_DOC_COMMENT', T_ML_COMMENT);
|
||||
|
||||
if (!defined('T_SIMPLE_TOKEN'))
|
||||
define('T_SIMPLE_TOKEN', 32567);
|
||||
|
||||
$this->debug_dump_tokens = $debug_token;
|
||||
$this->debug_dump_params = $debug_params;
|
||||
|
||||
$this->mysql_funcs =
|
||||
array(
|
||||
// PHP_FALIAS(mysql, mysql_db_query, NULL)
|
||||
'mysql' => new MySQLConverterTool_Function_DBQuery(),
|
||||
// in OO this is a property
|
||||
'mysql_affected_rows' => new MySQLConverterTool_Function_ConnParam('mysqli_affected_rows'),
|
||||
'mysql_change_user' => new MySQLConverterTool_Function_ChangeUser(),
|
||||
'mysql_client_encoding' => new MySQLConverterTool_Function_ConnParam('mysqli_character_set_name'),
|
||||
'mysql_close' => new MySQLConverterTool_Function_ConnParamBool('mysqli_close'),
|
||||
// pconnect has less params but they are not significant for mysqli_connect
|
||||
'mysql_connect' => new MySQLConverterTool_Function_Connect(),
|
||||
// PHP_FALIAS(mysql_createdb, mysql_create_db, NULL)
|
||||
'mysql_createdb' => new MySQLConverterTool_Function_CreateDB(),
|
||||
'mysql_create_db' => new MySQLConverterTool_Function_CreateDB(),
|
||||
'mysql_data_seek' => new MySQLConverterTool_Function_Generic('mysqli_data_seek'),
|
||||
'mysql_dbname' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_db_name' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_db_query' => new MySQLConverterTool_Function_DBQuery(),
|
||||
// PHP_FALIAS(mysql_dropdb, mysql_drop_db, NULL)
|
||||
'mysql_dropdb' => new MySQLConverterTool_Function_DropDB(),
|
||||
'mysql_drop_db' => new MySQLConverterTool_Function_DropDB(),
|
||||
// in OO this is a property
|
||||
'mysql_error' => new MySQLConverterTool_Function_Error('mysqli_error'),
|
||||
// in OO this is a property
|
||||
'mysql_errno' => new MySQLConverterTool_Function_Error('mysqli_errno'),
|
||||
'mysql_escape_string' => new MySQLConverterTool_Function_EscapeString('mysqli_real_escape_string'),
|
||||
'mysql_fetch_array' => new MySQLConverterTool_Function_Generic('mysqli_fetch_array'),
|
||||
'mysql_fetch_assoc' => new MySQLConverterTool_Function_Generic('mysqli_fetch_assoc'),
|
||||
'mysql_fetch_field' => new MySQLConverterTool_Function_FetchField(),
|
||||
'mysql_fetch_lengths' => new MySQLConverterTool_Function_GenericBoolean('mysqli_fetch_lengths'),
|
||||
'mysql_fetch_object' => new MySQLConverterTool_Function_Generic('mysqli_fetch_object'),
|
||||
'mysql_fetch_row' => new MySQLConverterTool_Function_Generic('mysqli_fetch_row'),
|
||||
// PHP_FALIAS(mysql_fieldflags, mysql_field_flags, NULL)
|
||||
'mysql_fieldflags' => new MySQLConverterTool_Function_FieldFlags(),
|
||||
'mysql_field_flags' => new MySQLConverterTool_Function_FieldFlags(),
|
||||
// PHP_FALIAS(mysql_fieldlen, mysql_field_len, NULL)
|
||||
'mysql_fieldlen' => new MySQLConverterTool_Function_FieldLen(),
|
||||
'mysql_field_len' => new MySQLConverterTool_Function_FieldLen(),
|
||||
// PHP_FALIAS(mysql_fieldname, mysql_field_name, NULL)
|
||||
'mysql_fieldname' => new MySQLConverterTool_Function_FieldName(),
|
||||
'mysql_field_name' => new MySQLConverterTool_Function_FieldName(),
|
||||
'mysql_field_seek' => new MySQLConverterTool_Function_GenericBoolean('mysqli_field_seek'),
|
||||
// PHP_FALIAS(mysql_fieldtable, mysql_field_table, NULL)
|
||||
'mysql_fieldtable' => new MySQLConverterTool_Function_FieldTable(),
|
||||
'mysql_field_table' => new MySQLConverterTool_Function_FieldTable(),
|
||||
// PHP_FALIAS(mysql_fieldtype, mysql_field_type, NULL)
|
||||
'mysql_fieldtype' => new MySQLConverterTool_Function_FieldType(),
|
||||
'mysql_field_type' => new MySQLConverterTool_Function_FieldType(),
|
||||
// PHP_FALIAS(mysql_freeresult, mysql_free_result, NULL)
|
||||
'mysql_freeresult' => new MySQLConverterTool_Function_FreeResult(),
|
||||
'mysql_free_result' => new MySQLConverterTool_Function_FreeResult(),
|
||||
'mysql_get_client_info' => new MySQLConverterTool_Function_Generic('mysqli_get_client_info'),
|
||||
// in OO this is a property
|
||||
'mysql_get_host_info' => new MySQLConverterTool_Function_ConnParamBool('mysqli_get_host_info'),
|
||||
// in OO this is a property
|
||||
'mysql_get_proto_info' => new MySQLConverterTool_Function_ConnParamBool('mysqli_get_proto_info'),
|
||||
// in OO this is a property
|
||||
'mysql_get_server_info' => new MySQLConverterTool_Function_ConnParamBool('mysqli_get_server_info'),
|
||||
'mysql_info' => new MySQLConverterTool_Function_ConnParam('mysqli_info'),
|
||||
'mysql_insert_id' => new MySQLConverterTool_Function_ConnParamBool('mysqli_insert_id'),
|
||||
// PHP_FALIAS(mysql_listdbs, mysql_list_dbs, NULL)
|
||||
'mysql_listdbs' => new MySQLConverterTool_Function_ListDBs(),
|
||||
'mysql_list_dbs' => new MySQLConverterTool_Function_ListDBs(),
|
||||
// PHP_FALIAS(mysql_listfields, mysql_list_fields, NULL)
|
||||
'mysql_listfields' => new MySQLConverterTool_Function_ListFields(),
|
||||
'mysql_list_fields' => new MySQLConverterTool_Function_ListFields(),
|
||||
'mysql_list_processes' => new MySQLConverterTool_Function_ListProcesses(),
|
||||
// PHP_FALIAS(mysql_listtables, mysql_list_tables, NULL)
|
||||
'mysql_listtables' => new MySQLConverterTool_Function_ListTables(),
|
||||
'mysql_list_tables' => new MySQLConverterTool_Function_ListTables(),
|
||||
// PHP_FALIAS(mysql_numfields, mysql_num_fields, NULL)
|
||||
'mysql_numfields' => new MySQLConverterTool_Function_Generic('mysqli_num_fields'),
|
||||
// in OO this is a property
|
||||
'mysql_num_fields' => new MySQLConverterTool_Function_GenericBoolean('mysqli_num_fields'),
|
||||
// PHP_FALIAS(mysql_numrows, mysql_num_rows, NULL)
|
||||
'mysql_numrows' => new MySQLConverterTool_Function_Generic('mysqli_num_rows'),
|
||||
// in OO this is a property
|
||||
'mysql_num_rows' => new MySQLConverterTool_Function_Generic('mysqli_num_rows'),
|
||||
// pconnect has less params but they are not significant for mysqli_connect
|
||||
'mysql_pconnect' => new MySQLConverterTool_Function_Connect(),
|
||||
'mysql_ping' => new MySQLConverterTool_Function_ConnParam('mysqli_ping'),
|
||||
'mysql_query' => new MySQLConverterTool_Function_ParReversed('mysqli_query'),
|
||||
'mysql_real_escape_string' => new MySQLConverterTool_Function_RealEscapeString('mysqli_real_escape_string'),
|
||||
// mysql_result -- Get result data
|
||||
// PHP_FALIAS(mysql_selectdb, mysql_select_db, NULL)
|
||||
'mysql_selectdb' => new MySQLConverterTool_Function_SelectDB(),
|
||||
'mysql_select_db' => new MySQLConverterTool_Function_SelectDB(),
|
||||
'mysql_stat' => new MySQLConverterTool_Function_ConnParam('mysqli_stat'),
|
||||
'mysql_tablename' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_table_name' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_thread_id' => new MySQLConverterTool_Function_ConnParam('mysqli_thread_id'),
|
||||
'mysql_unbuffered_query' => new MySQLConverterTool_Function_UnbufferedQuery(),
|
||||
);
|
||||
|
||||
} // end func __construct
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts the given source code
|
||||
*
|
||||
* @param string Source code to be converted
|
||||
* @return array Converted source code and status information
|
||||
*/
|
||||
public function convertString($source) {
|
||||
|
||||
$this->lineno = 0;
|
||||
$this->output = '';
|
||||
$this->tokens = token_get_all($source);
|
||||
$this->errors = array();
|
||||
$this->lineno = 1;
|
||||
|
||||
$this->funcs_found = 0;
|
||||
$this->funcs_converted = 0;
|
||||
|
||||
$this->scanner(0);
|
||||
|
||||
return array(
|
||||
'output' => $this->output,
|
||||
'found' => $this->funcs_found,
|
||||
'converted' => $this->funcs_converted,
|
||||
'errors' => $this->errors,
|
||||
);
|
||||
} // end func convertString
|
||||
|
||||
|
||||
/**
|
||||
* Reads a file and returns the converted source code
|
||||
*
|
||||
* @param strng filename
|
||||
* @param array Converted source and status information
|
||||
*/
|
||||
public function convertFile($filename) {
|
||||
|
||||
if (!file_exists($filename) || !is_readable($filename) || !is_file($filename)) {
|
||||
$ret = $this->convertString('');
|
||||
$ret['errors'][] = array('line' => -1, 'msg' => 'Cannot open file "' . $filename . '".');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return $this->convertString(file_get_contents($filename));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all files of a directory that have a certain name
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function getFilesOfDirectory($dir, $file_pattern = '*', Array $files = array()) {
|
||||
|
||||
if (!is_dir($dir) || !is_readable($dir))
|
||||
return $files;
|
||||
|
||||
$patterns = $this->buildRegularExpression($file_pattern);
|
||||
if (empty($patterns))
|
||||
return $files;
|
||||
|
||||
$dh = opendir($dir);
|
||||
if (!$dh)
|
||||
return $files;
|
||||
|
||||
while ($file = readdir($dh)) {
|
||||
if ('.' == $file || '..' == $file)
|
||||
continue;
|
||||
|
||||
$ffile = $dir . '/' . $file;
|
||||
if (is_dir($ffile))
|
||||
$files = $this->getFilesOfDirectory($ffile, $file_pattern, $files);
|
||||
|
||||
if (!is_file($ffile))
|
||||
continue;
|
||||
|
||||
$accept = false;
|
||||
foreach ($patterns as $k => $pattern) {
|
||||
if (preg_match('@' . $pattern . '$@i', $file)) {
|
||||
$accept = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($accept)
|
||||
$files[] = $ffile;
|
||||
}
|
||||
closedir($dh);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unsets the variable which stores the global (default) connection of ext/mysql
|
||||
*
|
||||
* This is a hack required by the test framework.
|
||||
*
|
||||
*/
|
||||
public function unsetGlobalConnection() {
|
||||
|
||||
$obj = new MySQLConverterTool_Function_Generic('mysqli_query');
|
||||
eval(sprintf('@mysqli_close(%s);', $obj->ston_name));
|
||||
eval(sprintf('if (isset(%s)) unset(%s);', $obj->ston_name, $obj->ston_name));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of functions that can be converted automatically
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSupportedFunctions() {
|
||||
|
||||
$ret = array_keys($this->mysql_funcs);
|
||||
sort($ret);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of functions that cannot be converted automatically
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUnsupportedFunctions() {
|
||||
|
||||
$ret = array_keys($this->mysql_funcs_not_supported);
|
||||
sort($ret);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
//
|
||||
// protected
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Scans the source and rebuilds a converted version of it
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
protected function scanner($level) {
|
||||
|
||||
// current parser state
|
||||
$state = self::STATE_NORMAL;
|
||||
|
||||
// list of function parameters
|
||||
$func_params = array();
|
||||
// current parameter value
|
||||
$curr_param = '';
|
||||
// current bracket nesting level
|
||||
$bracket_level = 0;
|
||||
// name of the currently processed function
|
||||
$func_name = '';
|
||||
// flag: does the currently parameter contain variables or constants?
|
||||
$param_dynamic = false;
|
||||
// flag for something that looks like a mysql_func call but is not followed by parameters
|
||||
$expect_param_brace_open = false;
|
||||
|
||||
|
||||
while (list( , $token) = each($this->tokens)) {
|
||||
|
||||
if (is_string($token)) {
|
||||
$id = T_SIMPLE_TOKEN;
|
||||
$token_name = 'T_SIMPLE_TOKEN';
|
||||
$text = $token;
|
||||
} else {
|
||||
list($id, $text) = $token;
|
||||
$token_name = token_name($id);
|
||||
}
|
||||
|
||||
// remember the current line number
|
||||
$lineno = $this->lineno;
|
||||
$this->lineno += $this->countLines($text);
|
||||
|
||||
if ($this->debug_dump_tokens) {
|
||||
|
||||
$this->debug_print('dump token',
|
||||
sprintf("[%-05d - %10s - %d - %-10s - %03d - %05d] %s",
|
||||
$lineno,
|
||||
$token_name,
|
||||
$expect_param_brace_open,
|
||||
$state,
|
||||
$bracket_level,
|
||||
strlen($text),
|
||||
htmlspecialchars($text))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
switch ($id) {
|
||||
|
||||
case T_COMMENT:
|
||||
case T_ML_COMMENT:
|
||||
case T_DOC_COMMENT:
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_NORMAL:
|
||||
$this->output .= $text;
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
// comment between func_name and comma
|
||||
break;
|
||||
|
||||
case self::STATE_PARAM_LIST:
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case T_SIMPLE_TOKEN:
|
||||
|
||||
switch ($state) {
|
||||
|
||||
case self::STATE_NORMAL:
|
||||
$this->output .= $text;
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
|
||||
switch ($text) {
|
||||
case '(':
|
||||
$state = self::STATE_PARAM_LIST;
|
||||
$func_params = array();
|
||||
$curr_param = NULL;
|
||||
$param_dynamic = false;
|
||||
$expect_param_brace_open = false;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
default:
|
||||
if ($expect_param_brace_open) {
|
||||
// something that looks like <mysql_func[...]> is not followed by an opening brace for <mysql_func([...]>
|
||||
$state = self::STATE_NORMAL;
|
||||
$this->funcs_found--;
|
||||
$expect_param_brace_open = 0;
|
||||
$steps = 0;
|
||||
$tmp = '';
|
||||
while (($token = prev($this->tokens)) && ($tmp != $func_name)) {
|
||||
if (is_array($token)) {
|
||||
$tmp = $token[1];
|
||||
} else {
|
||||
$tmp = $token;
|
||||
}
|
||||
$steps++;
|
||||
}
|
||||
while ($steps-- > 1) {
|
||||
$token = next($this->tokens);
|
||||
if (is_array($token))
|
||||
$tmp = $token[1];
|
||||
else
|
||||
$tmp = $token;
|
||||
$this->output .= $tmp;
|
||||
}
|
||||
next($this->tokens);
|
||||
break 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::STATE_PARAM_LIST:
|
||||
|
||||
switch ($text) {
|
||||
case ',':
|
||||
if ($bracket_level == 1) {
|
||||
$func_params[] = array('value' => $curr_param, 'dynamic' => $param_dynamic);
|
||||
$curr_param = '';
|
||||
$param_dynamic = false;
|
||||
} else {
|
||||
$curr_param .= $text;
|
||||
}
|
||||
// don't add to the curr_param
|
||||
break(2);
|
||||
|
||||
case '(':
|
||||
$bracket_level++;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
$bracket_level--;
|
||||
if ($bracket_level == 0) {
|
||||
// end of the parameter specification
|
||||
|
||||
if (!is_null($curr_param))
|
||||
$func_params[] = array('value' => $curr_param, 'dynamic' => $param_dynamic);
|
||||
|
||||
$curr_param = NULL;
|
||||
$param_dynamic = false;
|
||||
$state = self::STATE_NORMAL;
|
||||
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
array('name' => $func_name, 'params' => $func_params)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$level) {
|
||||
|
||||
list($handler_warning, $handler_code) = $this->mysql_funcs[$func_name]->handle($func_params);
|
||||
if (!is_null($handler_warning))
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] %s', $lineno, $handler_warning));
|
||||
|
||||
if (is_null($handler_code)) {
|
||||
$this->output .= $this->rebuildFunctionCode($func_name, $func_params, $handler_warning);
|
||||
} else {
|
||||
$this->funcs_converted++;
|
||||
$this->output .= $handler_code;
|
||||
}
|
||||
|
||||
} else {
|
||||
// we are in recursive call - return
|
||||
|
||||
list($handler_warning, $handler_code) = $this->mysql_funcs[$func_name]->handle($func_params);
|
||||
if (!is_null($handler_warning))
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] %s', $lineno, $handler_warning));
|
||||
|
||||
if (is_null($handler_code)) {
|
||||
return $this->rebuildFunctionCode($func_name, $func_params, $handler_warning);
|
||||
} else {
|
||||
$this->funcs_converted++;
|
||||
return $handler_code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case '.':
|
||||
case '&':
|
||||
case '^':
|
||||
case '|':
|
||||
case '&&':
|
||||
case '||':
|
||||
case 'and':
|
||||
case 'or':
|
||||
case 'xor':
|
||||
case '<<':
|
||||
case '>>':
|
||||
case '<':
|
||||
case '<=':
|
||||
case '>':
|
||||
case '>=':
|
||||
case '=':
|
||||
case '*':
|
||||
case '/':
|
||||
case '%':
|
||||
case '+':
|
||||
case '-':
|
||||
case '++':
|
||||
case '--':
|
||||
case '!':
|
||||
case '~':
|
||||
case '=':
|
||||
case '+=':
|
||||
case '-=':
|
||||
case '*=':
|
||||
case '/=':
|
||||
case '.=':
|
||||
case '%=':
|
||||
case '&=':
|
||||
case '|=':
|
||||
case '^=':
|
||||
case '<<=':
|
||||
case '>>=':
|
||||
case '?':
|
||||
case '==':
|
||||
case '!=':
|
||||
case '===':
|
||||
case '!==':
|
||||
case '(':
|
||||
case 'new':
|
||||
// forget it - this parameter value is build dynamically
|
||||
// we won't try to guess it's value using static code analysis
|
||||
// this needs to be checked manually
|
||||
$param_dynamic = true;
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
'Operator found in parameter. Assuming that the paramter value will be dynamic and cannot be foreseen.'
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case T_STRING:
|
||||
|
||||
if (isset($this->mysql_ext_consts[$text])) {
|
||||
|
||||
$text = $this->mysql_ext_consts[$text];
|
||||
|
||||
} else {
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_PARAM_LIST:
|
||||
// maybe a function call or constant as part of a parameter value?
|
||||
|
||||
if (isset($this->mysql_funcs_not_supported[$text])) {
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] Function "%s" is not supported for conversion! You must rewrite the converted code. The conversion is not complete. Consider rewriting your code first and rerunning the conversion tool"', $lineno, $text));
|
||||
|
||||
}
|
||||
|
||||
if (isset($this->mysql_funcs[$text])) {
|
||||
// return the current token and reparse it
|
||||
prev($this->tokens);
|
||||
// in the default of the outter switch add this to $curr_param
|
||||
$text = $this->scanner($level + 1);
|
||||
$param_dynamic = true;
|
||||
}
|
||||
// fall to default
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] We found a string between the function name "%s" and the parameter list. Looks like a syntax error in the source file. Please check!', $lineno, $func_name));
|
||||
|
||||
break;
|
||||
|
||||
case self::STATE_NORMAL:
|
||||
default:
|
||||
|
||||
if (isset($this->mysql_funcs_not_supported[$text])) {
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] Function "%s" is not supported for conversion! You must rewrite the converted code code. The conversion is not complete. Consider rewriting your code first and rerunning the conversion tool."', $lineno, $text));
|
||||
|
||||
}
|
||||
|
||||
if (isset($this->mysql_funcs[$text])) {
|
||||
$state = self::STATE_FUNC_FOUND;
|
||||
$func_name = $text;
|
||||
$bracket_level = 1;
|
||||
$this->funcs_found++;
|
||||
$expect_param_brace_open = true;
|
||||
|
||||
break(2);
|
||||
}
|
||||
|
||||
if ($text == 'is_resource') {
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] You are using is_resource(). Make sure that you do not use it to test for the return value of mysql_query(). mysql_query() returns a resource or a boolean value. mysqli_query() returns an object or a boolean value. If you check the return value of mysql_query like < if (is_resource($res = mysql_query())) [...] > the converted code will fail, because $res will be an object in ext/mysqli."', $lineno, $text));
|
||||
}
|
||||
// here we fall-through
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
|
||||
if ($id === T_CONSTANT_ENCAPSED_STRING) {
|
||||
/* try to detect function_exists('some_mysql_func'); */
|
||||
$prev_steps = 0;
|
||||
|
||||
if (isset($this->mysql_funcs[substr($text, 1, -1)]) &&
|
||||
$this->mysql_funcs[substr($text, 1, -1)]->new_name) {
|
||||
// strip quotes
|
||||
// move back because now 'some_mysql_func' will be returned by prev()
|
||||
$prev_steps = 1;
|
||||
$tmp_token = prev($this->tokens);
|
||||
|
||||
do {
|
||||
$tmp_token = prev($this->tokens);
|
||||
$prev_steps++;
|
||||
} while ($tmp_token[0] === T_WHITESPACE);
|
||||
|
||||
if ($tmp_token === '(') {
|
||||
|
||||
$tmp_token = prev($this->tokens);
|
||||
$prev_steps++;
|
||||
|
||||
if ($tmp_token[0] === T_STRING &&
|
||||
$tmp_token[1] === 'function_exists') {
|
||||
|
||||
$text = $text[0] . $this->mysql_funcs[substr($text, 1, -1)]->new_name . $text[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while ($prev_steps--)
|
||||
each($this->tokens);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_PARAM_LIST:
|
||||
|
||||
switch ($id) {
|
||||
|
||||
case T_VARIABLE:
|
||||
case T_FUNCTION:
|
||||
case T_CONST:
|
||||
// this is a variable, we cannot guess value of the parameter
|
||||
// using this static conversion approach
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
"Adding variable '$text' to current parameter."
|
||||
);
|
||||
}
|
||||
$param_dynamic = true;
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
|
||||
case T_WHITESPACE:
|
||||
default:
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
"Adding '$text' to current parameter."
|
||||
);
|
||||
}
|
||||
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] Please check your code for parse errors, we failed to parse "%s". Conversion will be incomplete!".', $lineno, $text));
|
||||
break;
|
||||
|
||||
default:
|
||||
case self::STATE_NORMAL:
|
||||
$this->output .= $text;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print a debug message
|
||||
*
|
||||
* @param string Message prefix
|
||||
* @param mixed Array or literal to print
|
||||
*/
|
||||
protected function debug_print($prefix, $var) {
|
||||
|
||||
if (is_scalar($var)) {
|
||||
printf("[%s/%s] %s\n",
|
||||
get_class($this),
|
||||
$prefix,
|
||||
$var);
|
||||
} else {
|
||||
printf("[%s/%s] ", get_class($this), $prefix);
|
||||
var_dump($var);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
} // end func debug_print
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of lines of a string
|
||||
*
|
||||
* @param string
|
||||
* @return int
|
||||
*/
|
||||
protected function countLines($text) {
|
||||
|
||||
$last_pos = 0;
|
||||
$lines = 0;
|
||||
while (($pos = strpos($text, "\n", $last_pos)) !== FALSE) {
|
||||
$last_pos = $pos + 1;
|
||||
$lines++;
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rebuilds the original function code based on function name and parameters and adds a comment with a warning after the last parameter
|
||||
*
|
||||
* @param string
|
||||
* @param array
|
||||
* @param string
|
||||
*/
|
||||
protected function rebuildFunctionCode($name, $params, $warning) {
|
||||
|
||||
$ret = $name . '(';
|
||||
if (count($params) > 0) {
|
||||
foreach ($params as $k => $param)
|
||||
$ret .= $param['value'] . ', ';
|
||||
$ret = substr($ret, 0, -2);
|
||||
}
|
||||
$ret .= ')';
|
||||
// $ret .= ' /* [MySQLConverterTool] ' . $warning . '*/)';
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Expands a user specified file pattern with * as the only pattern to a regular expression
|
||||
*
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
protected function buildRegularExpression($file_pattern) {
|
||||
|
||||
$parts = explode(',', $file_pattern);
|
||||
if (empty($parts))
|
||||
return array();
|
||||
|
||||
$ret = array();
|
||||
foreach ($parts as $k => $v)
|
||||
$ret[] = str_replace('\*', '.*', preg_quote($v, '@'));
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,18 @@
|
|||
Welcome to the MySQL ext/mysql->ext/mysqli Converter Tool.
|
||||
This tool helps you to migrate PHP files using the PHP
|
||||
MySQL extension to use the MySQLi extension.
|
||||
|
||||
Extract the archive into a directory on your web server. Open
|
||||
http://<yourwebserver>/<yourpath>/MySQLConverterTool/GUI/index.php
|
||||
for a Web GUI. If you want to work on the command line, try
|
||||
php -f cli.php.
|
||||
|
||||
Note that absolutely no security checks are performed
|
||||
by the tool which prevent users from trying to read and convert
|
||||
files (e.g. /etc/passwd). Make sure to add security measures,
|
||||
if needed.
|
||||
|
||||
If you want to run any tests, check the hints given
|
||||
in UnitTests/README.
|
||||
|
||||
Have fun!
|
|
@ -0,0 +1,445 @@
|
|||
<?php
|
||||
require_once('Converter.php');
|
||||
|
||||
/**
|
||||
* CLI Interface
|
||||
*
|
||||
* @category CLI
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Available since Release 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parse the command line options
|
||||
*
|
||||
* @param int
|
||||
* @param array
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function parseOptions($argc, $argv) {
|
||||
|
||||
$options = array();
|
||||
$error = null;
|
||||
|
||||
if ($argc < 2) {
|
||||
$error = 'No options given';
|
||||
return array($options, $error);
|
||||
}
|
||||
|
||||
reset($argv);
|
||||
|
||||
// skip $argv[0] - program name
|
||||
next($argv);
|
||||
|
||||
while (list($k, $arg) = each($argv)) {
|
||||
$arg = trim($arg);
|
||||
switch ($arg) {
|
||||
case '-f':
|
||||
if (list($k, $arg) = each($argv)) {
|
||||
$arg = trim($arg);
|
||||
if (substr($arg, 0, 1) == '-') {
|
||||
$error = '-f needs a file name';
|
||||
break 2;
|
||||
} else if (!file_exists($arg)) {
|
||||
$error = sprintf('"%s" does not exist', $arg);
|
||||
break 2;
|
||||
} else if (!is_file($arg)) {
|
||||
$error = sprintf('"%s" is not a file', $arg);
|
||||
break 2;
|
||||
} else if (!is_readable($arg)) {
|
||||
$error = sprintf('"%s" is not reabale', $arg);
|
||||
break 2;
|
||||
} else {
|
||||
$options['files'][$arg] = $arg;
|
||||
}
|
||||
} else {
|
||||
$error = sprintf('-f needs a file name');
|
||||
break 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-d':
|
||||
if (list($k, $arg) = each($argv)) {
|
||||
$arg = trim($arg);
|
||||
if (substr($arg, 0, 1) == '-') {
|
||||
$error = '-d needs a directory name';
|
||||
break 2;
|
||||
} else if (!file_exists($arg)) {
|
||||
$error = sprintf('"%s" does not exist', $arg);
|
||||
break 2;
|
||||
} else if (!is_dir($arg)) {
|
||||
$error = sprintf('"%s" is not a directory', $arg);
|
||||
break 2;
|
||||
} else if (!is_readable($arg)) {
|
||||
$error = sprintf('"%s" is not readable', $arg);
|
||||
break 2;
|
||||
} else {
|
||||
$options['directories'][$arg] = $arg;
|
||||
}
|
||||
} else {
|
||||
$error = sprintf('-d needs a directory name');
|
||||
break 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-s':
|
||||
if (list($k, $arg) = each($argv)) {
|
||||
$arg = trim($arg);
|
||||
if ('' == $arg) {
|
||||
$error = '-s expects a code snippet to follow the option';
|
||||
break 2;
|
||||
}
|
||||
$options['snippet'] = $arg;
|
||||
} else {
|
||||
$error = '-s expects a code snippet to follow the option';
|
||||
break 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-h':
|
||||
case '--help':
|
||||
$options['help'] = true;
|
||||
|
||||
case '-u':
|
||||
$options['update'] = true;
|
||||
break;
|
||||
|
||||
case '-b':
|
||||
$options['backup'] = true;
|
||||
$options['update'] = true;
|
||||
break;
|
||||
|
||||
case '-v':
|
||||
if (isset($options['quiet'])) {
|
||||
$error = 'You cannot use -v with -q';
|
||||
break 2;
|
||||
}
|
||||
$options['verbose'] = true;
|
||||
break;
|
||||
|
||||
case '-q':
|
||||
if (isset($options['verbose'])) {
|
||||
$error = 'You cannot use -q with -v';
|
||||
break 2;
|
||||
}
|
||||
$options['quiet'] = true;
|
||||
break;
|
||||
|
||||
case '-w':
|
||||
$options['warnings'] = true;
|
||||
break;
|
||||
|
||||
case '-p':
|
||||
if (list($k, $arg) = each($argv)) {
|
||||
$arg = trim($arg);
|
||||
if ('' == $arg) {
|
||||
$error = '-p needs a search pattern';
|
||||
break 2;
|
||||
} else {
|
||||
$options['pattern'] = $arg;
|
||||
}
|
||||
} else {
|
||||
$error = '-p needs a search pattern';
|
||||
break 2;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$error = sprintf('Invalid option "%s"', $arg);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($options, $error);
|
||||
} // end func parseOptions
|
||||
|
||||
|
||||
/**
|
||||
* Prints the help message with usage instructions
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
function printHelp($argv) {
|
||||
|
||||
printf("\n");
|
||||
printf("Usage of %s :\n\n", $argv[0]);
|
||||
printf("-f <file> Convert file\n");
|
||||
printf("-d <directory> Convert directory\n");
|
||||
printf('-p <pattern> File name pattern for -d, e.g. -p "*.php,*.php3". Default: *');
|
||||
printf("\n");
|
||||
printf("-s <code> Convert code snippet\n");
|
||||
printf("\n");
|
||||
printf("-u Update (modify) input file during the conversion\n");
|
||||
printf("-b Backup files to [original_name].org before they get updated\n\n");
|
||||
printf("-v verbose - print conversion details\n");
|
||||
printf("-w warnings - print errors/warnings, if any\n");
|
||||
printf("-q quiet - don't print the generated code\n");
|
||||
printf("\n\n");
|
||||
|
||||
} // end func printHelp
|
||||
|
||||
|
||||
/**
|
||||
* Returns a status description (OK, Error, Warning) based on the conversion result
|
||||
*
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
function getConversionStatus($conv_result) {
|
||||
|
||||
$status = null;
|
||||
if (($conv_result['found'] == $conv_result['converted']) && (count($conv_result['errors']) == 0)) {
|
||||
$status = 'OK';
|
||||
} else if (($conv_result['found'] == $conv_result['converted']) && (count($conv_result['errors']) > 0)) {
|
||||
$status = 'Warning';
|
||||
} else if (($conv_result['found'] != $conv_result['converted']) && (count($conv_result['errors']) > 0)) {
|
||||
$status = 'Error';
|
||||
}
|
||||
|
||||
return $status;
|
||||
} // end func getConversionStatus
|
||||
|
||||
|
||||
/**
|
||||
* Prints the overview summary with conversion details
|
||||
*
|
||||
* @param array
|
||||
* @param string
|
||||
* @param mixed
|
||||
*/
|
||||
function printConversionHeader($conv_result, $status, $file = null) {
|
||||
|
||||
if (!is_null($file)) {
|
||||
print "\n";
|
||||
printSeperator("File $file");
|
||||
print "\n";
|
||||
}
|
||||
|
||||
print "\n";
|
||||
printSeperator("Summary", '-');
|
||||
print "\n";
|
||||
|
||||
printf("Status: %s\n", $status);
|
||||
printf("Number of mysql_-functions found: %d\n", $conv_result['found']);
|
||||
printf("Number of mysql_-functions converted: %d\n", $conv_result['converted']);
|
||||
printf("Warnings/Errors: %d\n", count($conv_result['errors']));
|
||||
printf("Code length: %d Bytes\n", strlen($conv_result['output']));
|
||||
|
||||
} // end func printConversionHeader
|
||||
|
||||
|
||||
/**
|
||||
* Prints the conversion errors
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
function printConversionErrors($conv_result) {
|
||||
|
||||
print "\n";
|
||||
print "\n";
|
||||
printSeperator("Warnings/Errors", '-');
|
||||
print "\n";
|
||||
|
||||
foreach ($conv_result['errors'] as $k => $error) {
|
||||
printSeperator(sprintf("Warning/Error on line %d", $error['line']), ' ');
|
||||
print $error['msg'];
|
||||
print "\n";
|
||||
}
|
||||
} // end func printConversionErrors
|
||||
|
||||
|
||||
/**
|
||||
* Prints the generated source code
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
function printConversionOutput($conv_result, $verbose, $quiet) {
|
||||
|
||||
if ($verbose) {
|
||||
print "\n";
|
||||
print "\n";
|
||||
printSeperator("Generated code", '-');
|
||||
print "\n";
|
||||
}
|
||||
|
||||
if (!$quiet)
|
||||
print $conv_result['output'];
|
||||
|
||||
if ($verbose) {
|
||||
print "\n";
|
||||
print "\n";
|
||||
printSeperator("End of code", "-");
|
||||
print "\n";
|
||||
}
|
||||
|
||||
} // end func printConversionOutput
|
||||
|
||||
|
||||
/**
|
||||
* Converts a file
|
||||
*
|
||||
* @param string
|
||||
* @param bool
|
||||
*/
|
||||
function convertFile($file, $verbose, $quiet, $update, $backup, $warnings, $seperator = '#') {
|
||||
|
||||
$conv = new MySQLConverterTool_Converter();
|
||||
$ret = $conv->convertFile($file);
|
||||
$status = getConversionStatus($ret);
|
||||
|
||||
if ($quiet)
|
||||
printSeperator(sprintf('[ %-7s ] %s', $status, $file), $seperator);
|
||||
|
||||
if ($verbose)
|
||||
printConversionHeader($ret, $status, $file);
|
||||
|
||||
if ($backup) {
|
||||
$ffile = $file . '.org';
|
||||
if (file_exists($ffile) && !unlink($ffile)) {
|
||||
printf("Error:\n");
|
||||
printf("Cannot unlink old backup file '%s'. Check the file permissions.\n\n", $ffile);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rename($file, $ffile)) {
|
||||
printf("Error:\n");
|
||||
printf("Cannot rename '%s' to %s'. Check the file permissions.\n\n", $file, $ffile);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($verbose)
|
||||
printf("Backup created.\n", $ffile);
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
|
||||
if (!$fp = fopen($file, 'w')) {
|
||||
printf("Error:\n");
|
||||
printf("Cannot modify file '%s'. Check the file permissions.\n\n", $file);
|
||||
return;
|
||||
}
|
||||
fwrite($fp, $ret['output']);
|
||||
fclose($fp);
|
||||
|
||||
if ($verbose)
|
||||
printf("File updated/modified.\n", $file);
|
||||
|
||||
}
|
||||
|
||||
if (($verbose || $warnings) && count($ret['errors']) > 0)
|
||||
printConversionErrors($ret);
|
||||
|
||||
printConversionOutput($ret, $verbose, $quiet);
|
||||
} // end func convertFile
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function convertSnippet($code, $verbose, $quiet, $warnings, $seperator = '#') {
|
||||
|
||||
$conv = new MySQLConverterTool_Converter();
|
||||
$ret = $conv->convertString($code);
|
||||
$status = getConversionStatus($ret);
|
||||
|
||||
if ($quiet)
|
||||
printSeperator('Snippet', $seperator);
|
||||
|
||||
if ($verbose)
|
||||
printConversionHeader($ret, $status, NULL);
|
||||
|
||||
if (($verbose || $warnings) && count($ret['errors']) > 0)
|
||||
printConversionErrors($ret);
|
||||
|
||||
printConversionOutput($ret, $verbose, $quiet);
|
||||
} // end func convertSnippet
|
||||
|
||||
|
||||
/**
|
||||
* Helper: prints a line with a title
|
||||
*
|
||||
* @param string
|
||||
* @param string
|
||||
*/
|
||||
function printSeperator($title, $seperator = '#') {
|
||||
|
||||
$len = strlen($title) + 2;
|
||||
|
||||
$num = 1;
|
||||
// $num = max(floor((80 - $len) / 2), 0);
|
||||
for ($i = 0; $i < $num; $i++)
|
||||
print $seperator;
|
||||
|
||||
printf(' %s ', $title);
|
||||
|
||||
if ($num > 0) {
|
||||
$num = 80 - $num - $len;
|
||||
for ($i = 0; $i < $num; $i++)
|
||||
print $seperator;
|
||||
}
|
||||
|
||||
print "\n";
|
||||
|
||||
} // end func printSeperator
|
||||
|
||||
|
||||
if (!isset($argc) || !isset($argv)) {
|
||||
// redirect to the web gui
|
||||
// or maybe die("This is the command line interface, use php -f cli.php to run it! Open index.php for the web interface."); ?
|
||||
header('Location: GUI/index.php');
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
list($options, $error) = parseOptions($argc, $argv);
|
||||
if (!is_null($error) || empty($options) || isset($options['help'])) {
|
||||
// some sort of trouble or help output requested
|
||||
|
||||
if (!is_null($error)) {
|
||||
printf("\n");
|
||||
printf("Error: %s\n", $error);
|
||||
}
|
||||
printHelp($argv);
|
||||
|
||||
} else {
|
||||
|
||||
print "\n";
|
||||
|
||||
if (!empty($options['files'])) {
|
||||
foreach ($options['files'] as $k => $file)
|
||||
convertFile($file, isset($options['verbose']), isset($options['quiet']), isset($options['update']), isset($options['backup']), isset($options['warnings']));
|
||||
}
|
||||
|
||||
if (!empty($options['directories'])) {
|
||||
$conv = new MySQLConverterTool_Converter();
|
||||
foreach ($options['directories'] as $k => $directory) {
|
||||
$files = $conv->getFilesOfDirectory($directory, (isset($options['pattern'])) ? $options['pattern'] : '');
|
||||
if (empty($files)) {
|
||||
printSeperator(sprintf('No files found in "%s"', $directory), '*');
|
||||
print "\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
printSeperator(sprintf('Directory "%s"', $directory), '*');
|
||||
print "\n";
|
||||
foreach ($files as $k => $file) {
|
||||
convertFile($file, isset($options['verbose']), isset($options['quiet']), isset($options['update']), isset($options['backup']), isset($options['warnings']), ' ');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['snippet']))
|
||||
convertSnippet($options['snippet'], isset($options['verbose']), isset($options['quiet']), isset($options['warnings']));
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,16 @@
|
|||
<?PHP
|
||||
/**
|
||||
* GUI: Redirects to the GUI directory
|
||||
*
|
||||
* @category GUI
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Available since Release 1.0
|
||||
*/
|
||||
header('Location: GUI/index.php');
|
||||
exit(0);
|
||||
?>
|
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 71
|
||||
/svnpublic/mysqli_converter/!svn/ver/3/MySQLConverterTool/Converter.php
|
||||
END
|
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 64
|
||||
/svnpublic/mysqli_converter/!svn/ver/3/MySQLConverterTool/README
|
||||
END
|
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 65
|
||||
/svnpublic/mysqli_converter/!svn/ver/3/MySQLConverterTool/cli.php
|
||||
END
|
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 67
|
||||
/svnpublic/mysqli_converter/!svn/ver/3/MySQLConverterTool/index.php
|
||||
END
|
|
@ -0,0 +1,936 @@
|
|||
<?PHP
|
||||
require_once('Function/ChangeUser.php');
|
||||
require_once('Function/Connect.php');
|
||||
require_once('Function/ConnParam.php');
|
||||
require_once('Function/ConnParamBool.php');
|
||||
require_once('Function/CreateDB.php');
|
||||
require_once('Function/DBQuery.php');
|
||||
require_once('Function/DropDB.php');
|
||||
require_once('Function/Error.php');
|
||||
require_once('Function/EscapeString.php');
|
||||
require_once('Function/FetchField.php');
|
||||
require_once('Function/FieldFlags.php');
|
||||
require_once('Function/FieldLen.php');
|
||||
require_once('Function/FieldName.php');
|
||||
require_once('Function/FieldTable.php');
|
||||
require_once('Function/FieldType.php');
|
||||
require_once('Function/FreeResult.php');
|
||||
require_once('Function/Generic.php');
|
||||
require_once('Function/GenericBoolean.php');
|
||||
require_once('Function/ListDBs.php');
|
||||
require_once('Function/ListFields.php');
|
||||
require_once('Function/ListProcesses.php');
|
||||
require_once('Function/ListTables.php');
|
||||
require_once('Function/ParReversed.php');
|
||||
require_once('Function/RealEscapeString.php');
|
||||
require_once('Function/SelectDB.php');
|
||||
require_once('Function/Tablename.php');
|
||||
require_once('Function/UnbufferedQuery.php');
|
||||
|
||||
/**
|
||||
* ext/mysql->ext/mysqli Converter
|
||||
*
|
||||
* @category Converter
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>, Saif Lacrimosa <cool2309@gmail.com>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Converter {
|
||||
|
||||
//
|
||||
// protected
|
||||
//
|
||||
|
||||
/**
|
||||
* Scanner state constant
|
||||
*
|
||||
* @const
|
||||
* @access protected
|
||||
*/
|
||||
const STATE_NORMAL = 'normal_state';
|
||||
|
||||
|
||||
/**
|
||||
* Scanner state constant
|
||||
*
|
||||
* @const
|
||||
* @access protectd
|
||||
*/
|
||||
const STATE_FUNC_FOUND = 'func_found';
|
||||
|
||||
|
||||
/**
|
||||
* Scanner state constant
|
||||
*
|
||||
* @const
|
||||
* @access protected
|
||||
*/
|
||||
const STATE_PARAM_LIST = 'parameter_list';
|
||||
|
||||
|
||||
/**
|
||||
* Converted (= resulting) source code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $output = '';
|
||||
|
||||
|
||||
/**
|
||||
* List of errors which occured during the conversion
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
|
||||
/**
|
||||
* List of PHP token
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tokens = array();
|
||||
|
||||
|
||||
/**
|
||||
* Mapping of ext/mysql -> ext/mysqli constants
|
||||
*
|
||||
*/
|
||||
protected $mysql_ext_consts = array(
|
||||
'MYSQL_CLIENT_COMPRESS' => 'MYSQLI_CLIENT_COMPRESS',
|
||||
'MYSQL_CLIENT_IGNORE_SPACE' => 'MYSQLI_CLIENT_IGNORE_SPACE',
|
||||
'MYSQL_CLIENT_INTERACTIVE' => 'MYSQLI_CLIENT_INTERACTIVE',
|
||||
'MYSQL_CLIENT_SSL' => 'MYSQLI_CLIENT_SSL',
|
||||
'MYSQL_ASSOC' => 'MYSQLI_ASSOC',
|
||||
'MYSQL_BOTH' => 'MYSQLI_BOTH',
|
||||
'MYSQL_NUM' => 'MYSQLI_NUM',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Number of functions found in the given source
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $funcs_found = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Number of functions converted in the given source
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $funcs_converted = 0;
|
||||
|
||||
|
||||
/**
|
||||
* List of functions that are not supported
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mysql_funcs_not_supported = array(
|
||||
// rewrite the ugly mysql_result calls manually!
|
||||
'mysql_result' => true,
|
||||
// whatever that function is...
|
||||
'mysql_fetch_field2' => true,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* List of functions that can be converted
|
||||
*
|
||||
* Acts as kind of a function pointer list, but with objects
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mysql_funcs = array();
|
||||
|
||||
|
||||
/**
|
||||
* Flag: enable token debug output?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug_dump_tokens = false;
|
||||
|
||||
|
||||
/**
|
||||
* Flag: enable parameter parsing debug output?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $debug_dump_params = false;
|
||||
|
||||
|
||||
/**
|
||||
* Current line number during the parsing process
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineno = 0;
|
||||
|
||||
|
||||
//
|
||||
// public
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param bool Turn on debug output of scanner token?
|
||||
* @param bool Turn on debug output of function parameters?
|
||||
*/
|
||||
public function __construct($debug_token = false, $debug_params = false) {
|
||||
|
||||
if (!function_exists('token_name')) {
|
||||
// HACK FIXME
|
||||
die('ext/tokenizer is needed!\n');
|
||||
}
|
||||
|
||||
if (!defined('T_ML_COMMENT'))
|
||||
define('T_ML_COMMENT', T_COMMENT);
|
||||
|
||||
if (!defined('T_DOC_COMMENT'))
|
||||
define('T_DOC_COMMENT', T_ML_COMMENT);
|
||||
|
||||
if (!defined('T_SIMPLE_TOKEN'))
|
||||
define('T_SIMPLE_TOKEN', 32567);
|
||||
|
||||
$this->debug_dump_tokens = $debug_token;
|
||||
$this->debug_dump_params = $debug_params;
|
||||
|
||||
$this->mysql_funcs =
|
||||
array(
|
||||
// PHP_FALIAS(mysql, mysql_db_query, NULL)
|
||||
'mysql' => new MySQLConverterTool_Function_DBQuery(),
|
||||
// in OO this is a property
|
||||
'mysql_affected_rows' => new MySQLConverterTool_Function_ConnParam('mysqli_affected_rows'),
|
||||
'mysql_change_user' => new MySQLConverterTool_Function_ChangeUser(),
|
||||
'mysql_client_encoding' => new MySQLConverterTool_Function_ConnParam('mysqli_character_set_name'),
|
||||
'mysql_close' => new MySQLConverterTool_Function_ConnParamBool('mysqli_close'),
|
||||
// pconnect has less params but they are not significant for mysqli_connect
|
||||
'mysql_connect' => new MySQLConverterTool_Function_Connect(),
|
||||
// PHP_FALIAS(mysql_createdb, mysql_create_db, NULL)
|
||||
'mysql_createdb' => new MySQLConverterTool_Function_CreateDB(),
|
||||
'mysql_create_db' => new MySQLConverterTool_Function_CreateDB(),
|
||||
'mysql_data_seek' => new MySQLConverterTool_Function_Generic('mysqli_data_seek'),
|
||||
'mysql_dbname' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_db_name' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_db_query' => new MySQLConverterTool_Function_DBQuery(),
|
||||
// PHP_FALIAS(mysql_dropdb, mysql_drop_db, NULL)
|
||||
'mysql_dropdb' => new MySQLConverterTool_Function_DropDB(),
|
||||
'mysql_drop_db' => new MySQLConverterTool_Function_DropDB(),
|
||||
// in OO this is a property
|
||||
'mysql_error' => new MySQLConverterTool_Function_Error('mysqli_error'),
|
||||
// in OO this is a property
|
||||
'mysql_errno' => new MySQLConverterTool_Function_Error('mysqli_errno'),
|
||||
'mysql_escape_string' => new MySQLConverterTool_Function_EscapeString('mysqli_real_escape_string'),
|
||||
'mysql_fetch_array' => new MySQLConverterTool_Function_Generic('mysqli_fetch_array'),
|
||||
'mysql_fetch_assoc' => new MySQLConverterTool_Function_Generic('mysqli_fetch_assoc'),
|
||||
'mysql_fetch_field' => new MySQLConverterTool_Function_FetchField(),
|
||||
'mysql_fetch_lengths' => new MySQLConverterTool_Function_GenericBoolean('mysqli_fetch_lengths'),
|
||||
'mysql_fetch_object' => new MySQLConverterTool_Function_Generic('mysqli_fetch_object'),
|
||||
'mysql_fetch_row' => new MySQLConverterTool_Function_Generic('mysqli_fetch_row'),
|
||||
// PHP_FALIAS(mysql_fieldflags, mysql_field_flags, NULL)
|
||||
'mysql_fieldflags' => new MySQLConverterTool_Function_FieldFlags(),
|
||||
'mysql_field_flags' => new MySQLConverterTool_Function_FieldFlags(),
|
||||
// PHP_FALIAS(mysql_fieldlen, mysql_field_len, NULL)
|
||||
'mysql_fieldlen' => new MySQLConverterTool_Function_FieldLen(),
|
||||
'mysql_field_len' => new MySQLConverterTool_Function_FieldLen(),
|
||||
// PHP_FALIAS(mysql_fieldname, mysql_field_name, NULL)
|
||||
'mysql_fieldname' => new MySQLConverterTool_Function_FieldName(),
|
||||
'mysql_field_name' => new MySQLConverterTool_Function_FieldName(),
|
||||
'mysql_field_seek' => new MySQLConverterTool_Function_GenericBoolean('mysqli_field_seek'),
|
||||
// PHP_FALIAS(mysql_fieldtable, mysql_field_table, NULL)
|
||||
'mysql_fieldtable' => new MySQLConverterTool_Function_FieldTable(),
|
||||
'mysql_field_table' => new MySQLConverterTool_Function_FieldTable(),
|
||||
// PHP_FALIAS(mysql_fieldtype, mysql_field_type, NULL)
|
||||
'mysql_fieldtype' => new MySQLConverterTool_Function_FieldType(),
|
||||
'mysql_field_type' => new MySQLConverterTool_Function_FieldType(),
|
||||
// PHP_FALIAS(mysql_freeresult, mysql_free_result, NULL)
|
||||
'mysql_freeresult' => new MySQLConverterTool_Function_FreeResult(),
|
||||
'mysql_free_result' => new MySQLConverterTool_Function_FreeResult(),
|
||||
'mysql_get_client_info' => new MySQLConverterTool_Function_Generic('mysqli_get_client_info'),
|
||||
// in OO this is a property
|
||||
'mysql_get_host_info' => new MySQLConverterTool_Function_ConnParamBool('mysqli_get_host_info'),
|
||||
// in OO this is a property
|
||||
'mysql_get_proto_info' => new MySQLConverterTool_Function_ConnParamBool('mysqli_get_proto_info'),
|
||||
// in OO this is a property
|
||||
'mysql_get_server_info' => new MySQLConverterTool_Function_ConnParamBool('mysqli_get_server_info'),
|
||||
'mysql_info' => new MySQLConverterTool_Function_ConnParam('mysqli_info'),
|
||||
'mysql_insert_id' => new MySQLConverterTool_Function_ConnParamBool('mysqli_insert_id'),
|
||||
// PHP_FALIAS(mysql_listdbs, mysql_list_dbs, NULL)
|
||||
'mysql_listdbs' => new MySQLConverterTool_Function_ListDBs(),
|
||||
'mysql_list_dbs' => new MySQLConverterTool_Function_ListDBs(),
|
||||
// PHP_FALIAS(mysql_listfields, mysql_list_fields, NULL)
|
||||
'mysql_listfields' => new MySQLConverterTool_Function_ListFields(),
|
||||
'mysql_list_fields' => new MySQLConverterTool_Function_ListFields(),
|
||||
'mysql_list_processes' => new MySQLConverterTool_Function_ListProcesses(),
|
||||
// PHP_FALIAS(mysql_listtables, mysql_list_tables, NULL)
|
||||
'mysql_listtables' => new MySQLConverterTool_Function_ListTables(),
|
||||
'mysql_list_tables' => new MySQLConverterTool_Function_ListTables(),
|
||||
// PHP_FALIAS(mysql_numfields, mysql_num_fields, NULL)
|
||||
'mysql_numfields' => new MySQLConverterTool_Function_Generic('mysqli_num_fields'),
|
||||
// in OO this is a property
|
||||
'mysql_num_fields' => new MySQLConverterTool_Function_GenericBoolean('mysqli_num_fields'),
|
||||
// PHP_FALIAS(mysql_numrows, mysql_num_rows, NULL)
|
||||
'mysql_numrows' => new MySQLConverterTool_Function_Generic('mysqli_num_rows'),
|
||||
// in OO this is a property
|
||||
'mysql_num_rows' => new MySQLConverterTool_Function_Generic('mysqli_num_rows'),
|
||||
// pconnect has less params but they are not significant for mysqli_connect
|
||||
'mysql_pconnect' => new MySQLConverterTool_Function_Connect(),
|
||||
'mysql_ping' => new MySQLConverterTool_Function_ConnParam('mysqli_ping'),
|
||||
'mysql_query' => new MySQLConverterTool_Function_ParReversed('mysqli_query'),
|
||||
'mysql_real_escape_string' => new MySQLConverterTool_Function_RealEscapeString('mysqli_real_escape_string'),
|
||||
// mysql_result -- Get result data
|
||||
// PHP_FALIAS(mysql_selectdb, mysql_select_db, NULL)
|
||||
'mysql_selectdb' => new MySQLConverterTool_Function_SelectDB(),
|
||||
'mysql_select_db' => new MySQLConverterTool_Function_SelectDB(),
|
||||
'mysql_stat' => new MySQLConverterTool_Function_ConnParam('mysqli_stat'),
|
||||
'mysql_tablename' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_table_name' => new MySQLConverterTool_Function_Tablename(),
|
||||
'mysql_thread_id' => new MySQLConverterTool_Function_ConnParam('mysqli_thread_id'),
|
||||
'mysql_unbuffered_query' => new MySQLConverterTool_Function_UnbufferedQuery(),
|
||||
);
|
||||
|
||||
} // end func __construct
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts the given source code
|
||||
*
|
||||
* @param string Source code to be converted
|
||||
* @return array Converted source code and status information
|
||||
*/
|
||||
public function convertString($source) {
|
||||
|
||||
$this->lineno = 0;
|
||||
$this->output = '';
|
||||
$this->tokens = token_get_all($source);
|
||||
$this->errors = array();
|
||||
$this->lineno = 1;
|
||||
|
||||
$this->funcs_found = 0;
|
||||
$this->funcs_converted = 0;
|
||||
|
||||
$this->scanner(0);
|
||||
|
||||
return array(
|
||||
'output' => $this->output,
|
||||
'found' => $this->funcs_found,
|
||||
'converted' => $this->funcs_converted,
|
||||
'errors' => $this->errors,
|
||||
);
|
||||
} // end func convertString
|
||||
|
||||
|
||||
/**
|
||||
* Reads a file and returns the converted source code
|
||||
*
|
||||
* @param strng filename
|
||||
* @param array Converted source and status information
|
||||
*/
|
||||
public function convertFile($filename) {
|
||||
|
||||
if (!file_exists($filename) || !is_readable($filename) || !is_file($filename)) {
|
||||
$ret = $this->convertString('');
|
||||
$ret['errors'][] = array('line' => -1, 'msg' => 'Cannot open file "' . $filename . '".');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return $this->convertString(file_get_contents($filename));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all files of a directory that have a certain name
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function getFilesOfDirectory($dir, $file_pattern = '*', Array $files = array()) {
|
||||
|
||||
if (!is_dir($dir) || !is_readable($dir))
|
||||
return $files;
|
||||
|
||||
$patterns = $this->buildRegularExpression($file_pattern);
|
||||
if (empty($patterns))
|
||||
return $files;
|
||||
|
||||
$dh = opendir($dir);
|
||||
if (!$dh)
|
||||
return $files;
|
||||
|
||||
while ($file = readdir($dh)) {
|
||||
if ('.' == $file || '..' == $file)
|
||||
continue;
|
||||
|
||||
$ffile = $dir . '/' . $file;
|
||||
if (is_dir($ffile))
|
||||
$files = $this->getFilesOfDirectory($ffile, $file_pattern, $files);
|
||||
|
||||
if (!is_file($ffile))
|
||||
continue;
|
||||
|
||||
$accept = false;
|
||||
foreach ($patterns as $k => $pattern) {
|
||||
if (preg_match('@' . $pattern . '$@i', $file)) {
|
||||
$accept = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($accept)
|
||||
$files[] = $ffile;
|
||||
}
|
||||
closedir($dh);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unsets the variable which stores the global (default) connection of ext/mysql
|
||||
*
|
||||
* This is a hack required by the test framework.
|
||||
*
|
||||
*/
|
||||
public function unsetGlobalConnection() {
|
||||
|
||||
$obj = new MySQLConverterTool_Function_Generic('mysqli_query');
|
||||
eval(sprintf('@mysqli_close(%s);', $obj->ston_name));
|
||||
eval(sprintf('if (isset(%s)) unset(%s);', $obj->ston_name, $obj->ston_name));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of functions that can be converted automatically
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSupportedFunctions() {
|
||||
|
||||
$ret = array_keys($this->mysql_funcs);
|
||||
sort($ret);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of functions that cannot be converted automatically
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUnsupportedFunctions() {
|
||||
|
||||
$ret = array_keys($this->mysql_funcs_not_supported);
|
||||
sort($ret);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
//
|
||||
// protected
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Scans the source and rebuilds a converted version of it
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
protected function scanner($level) {
|
||||
|
||||
// current parser state
|
||||
$state = self::STATE_NORMAL;
|
||||
|
||||
// list of function parameters
|
||||
$func_params = array();
|
||||
// current parameter value
|
||||
$curr_param = '';
|
||||
// current bracket nesting level
|
||||
$bracket_level = 0;
|
||||
// name of the currently processed function
|
||||
$func_name = '';
|
||||
// flag: does the currently parameter contain variables or constants?
|
||||
$param_dynamic = false;
|
||||
// flag for something that looks like a mysql_func call but is not followed by parameters
|
||||
$expect_param_brace_open = false;
|
||||
|
||||
|
||||
while (list( , $token) = each($this->tokens)) {
|
||||
|
||||
if (is_string($token)) {
|
||||
$id = T_SIMPLE_TOKEN;
|
||||
$token_name = 'T_SIMPLE_TOKEN';
|
||||
$text = $token;
|
||||
} else {
|
||||
list($id, $text) = $token;
|
||||
$token_name = token_name($id);
|
||||
}
|
||||
|
||||
// remember the current line number
|
||||
$lineno = $this->lineno;
|
||||
$this->lineno += $this->countLines($text);
|
||||
|
||||
if ($this->debug_dump_tokens) {
|
||||
|
||||
$this->debug_print('dump token',
|
||||
sprintf("[%-05d - %10s - %d - %-10s - %03d - %05d] %s",
|
||||
$lineno,
|
||||
$token_name,
|
||||
$expect_param_brace_open,
|
||||
$state,
|
||||
$bracket_level,
|
||||
strlen($text),
|
||||
htmlspecialchars($text))
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
switch ($id) {
|
||||
|
||||
case T_COMMENT:
|
||||
case T_ML_COMMENT:
|
||||
case T_DOC_COMMENT:
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_NORMAL:
|
||||
$this->output .= $text;
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
// comment between func_name and comma
|
||||
break;
|
||||
|
||||
case self::STATE_PARAM_LIST:
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case T_SIMPLE_TOKEN:
|
||||
|
||||
switch ($state) {
|
||||
|
||||
case self::STATE_NORMAL:
|
||||
$this->output .= $text;
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
|
||||
switch ($text) {
|
||||
case '(':
|
||||
$state = self::STATE_PARAM_LIST;
|
||||
$func_params = array();
|
||||
$curr_param = NULL;
|
||||
$param_dynamic = false;
|
||||
$expect_param_brace_open = false;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
default:
|
||||
if ($expect_param_brace_open) {
|
||||
// something that looks like <mysql_func[...]> is not followed by an opening brace for <mysql_func([...]>
|
||||
$state = self::STATE_NORMAL;
|
||||
$this->funcs_found--;
|
||||
$expect_param_brace_open = 0;
|
||||
$steps = 0;
|
||||
$tmp = '';
|
||||
while (($token = prev($this->tokens)) && ($tmp != $func_name)) {
|
||||
if (is_array($token)) {
|
||||
$tmp = $token[1];
|
||||
} else {
|
||||
$tmp = $token;
|
||||
}
|
||||
$steps++;
|
||||
}
|
||||
while ($steps-- > 1) {
|
||||
$token = next($this->tokens);
|
||||
if (is_array($token))
|
||||
$tmp = $token[1];
|
||||
else
|
||||
$tmp = $token;
|
||||
$this->output .= $tmp;
|
||||
}
|
||||
next($this->tokens);
|
||||
break 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::STATE_PARAM_LIST:
|
||||
|
||||
switch ($text) {
|
||||
case ',':
|
||||
if ($bracket_level == 1) {
|
||||
$func_params[] = array('value' => $curr_param, 'dynamic' => $param_dynamic);
|
||||
$curr_param = '';
|
||||
$param_dynamic = false;
|
||||
} else {
|
||||
$curr_param .= $text;
|
||||
}
|
||||
// don't add to the curr_param
|
||||
break(2);
|
||||
|
||||
case '(':
|
||||
$bracket_level++;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
$bracket_level--;
|
||||
if ($bracket_level == 0) {
|
||||
// end of the parameter specification
|
||||
|
||||
if (!is_null($curr_param))
|
||||
$func_params[] = array('value' => $curr_param, 'dynamic' => $param_dynamic);
|
||||
|
||||
$curr_param = NULL;
|
||||
$param_dynamic = false;
|
||||
$state = self::STATE_NORMAL;
|
||||
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
array('name' => $func_name, 'params' => $func_params)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$level) {
|
||||
|
||||
list($handler_warning, $handler_code) = $this->mysql_funcs[$func_name]->handle($func_params);
|
||||
if (!is_null($handler_warning))
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] %s', $lineno, $handler_warning));
|
||||
|
||||
if (is_null($handler_code)) {
|
||||
$this->output .= $this->rebuildFunctionCode($func_name, $func_params, $handler_warning);
|
||||
} else {
|
||||
$this->funcs_converted++;
|
||||
$this->output .= $handler_code;
|
||||
}
|
||||
|
||||
} else {
|
||||
// we are in recursive call - return
|
||||
|
||||
list($handler_warning, $handler_code) = $this->mysql_funcs[$func_name]->handle($func_params);
|
||||
if (!is_null($handler_warning))
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] %s', $lineno, $handler_warning));
|
||||
|
||||
if (is_null($handler_code)) {
|
||||
return $this->rebuildFunctionCode($func_name, $func_params, $handler_warning);
|
||||
} else {
|
||||
$this->funcs_converted++;
|
||||
return $handler_code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case '.':
|
||||
case '&':
|
||||
case '^':
|
||||
case '|':
|
||||
case '&&':
|
||||
case '||':
|
||||
case 'and':
|
||||
case 'or':
|
||||
case 'xor':
|
||||
case '<<':
|
||||
case '>>':
|
||||
case '<':
|
||||
case '<=':
|
||||
case '>':
|
||||
case '>=':
|
||||
case '=':
|
||||
case '*':
|
||||
case '/':
|
||||
case '%':
|
||||
case '+':
|
||||
case '-':
|
||||
case '++':
|
||||
case '--':
|
||||
case '!':
|
||||
case '~':
|
||||
case '=':
|
||||
case '+=':
|
||||
case '-=':
|
||||
case '*=':
|
||||
case '/=':
|
||||
case '.=':
|
||||
case '%=':
|
||||
case '&=':
|
||||
case '|=':
|
||||
case '^=':
|
||||
case '<<=':
|
||||
case '>>=':
|
||||
case '?':
|
||||
case '==':
|
||||
case '!=':
|
||||
case '===':
|
||||
case '!==':
|
||||
case '(':
|
||||
case 'new':
|
||||
// forget it - this parameter value is build dynamically
|
||||
// we won't try to guess it's value using static code analysis
|
||||
// this needs to be checked manually
|
||||
$param_dynamic = true;
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
'Operator found in parameter. Assuming that the paramter value will be dynamic and cannot be foreseen.'
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case T_STRING:
|
||||
|
||||
if (isset($this->mysql_ext_consts[$text])) {
|
||||
|
||||
$text = $this->mysql_ext_consts[$text];
|
||||
|
||||
} else {
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_PARAM_LIST:
|
||||
// maybe a function call or constant as part of a parameter value?
|
||||
|
||||
if (isset($this->mysql_funcs_not_supported[$text])) {
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] Function "%s" is not supported for conversion! You must rewrite the converted code. The conversion is not complete. Consider rewriting your code first and rerunning the conversion tool"', $lineno, $text));
|
||||
|
||||
}
|
||||
|
||||
if (isset($this->mysql_funcs[$text])) {
|
||||
// return the current token and reparse it
|
||||
prev($this->tokens);
|
||||
// in the default of the outter switch add this to $curr_param
|
||||
$text = $this->scanner($level + 1);
|
||||
$param_dynamic = true;
|
||||
}
|
||||
// fall to default
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] We found a string between the function name "%s" and the parameter list. Looks like a syntax error in the source file. Please check!', $lineno, $func_name));
|
||||
|
||||
break;
|
||||
|
||||
case self::STATE_NORMAL:
|
||||
default:
|
||||
|
||||
if (isset($this->mysql_funcs_not_supported[$text])) {
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] Function "%s" is not supported for conversion! You must rewrite the converted code code. The conversion is not complete. Consider rewriting your code first and rerunning the conversion tool."', $lineno, $text));
|
||||
|
||||
}
|
||||
|
||||
if (isset($this->mysql_funcs[$text])) {
|
||||
$state = self::STATE_FUNC_FOUND;
|
||||
$func_name = $text;
|
||||
$bracket_level = 1;
|
||||
$this->funcs_found++;
|
||||
$expect_param_brace_open = true;
|
||||
|
||||
break(2);
|
||||
}
|
||||
|
||||
if ($text == 'is_resource') {
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] You are using is_resource(). Make sure that you do not use it to test for the return value of mysql_query(). mysql_query() returns a resource or a boolean value. mysqli_query() returns an object or a boolean value. If you check the return value of mysql_query like < if (is_resource($res = mysql_query())) [...] > the converted code will fail, because $res will be an object in ext/mysqli."', $lineno, $text));
|
||||
}
|
||||
// here we fall-through
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
|
||||
if ($id === T_CONSTANT_ENCAPSED_STRING) {
|
||||
/* try to detect function_exists('some_mysql_func'); */
|
||||
$prev_steps = 0;
|
||||
|
||||
if (isset($this->mysql_funcs[substr($text, 1, -1)]) &&
|
||||
$this->mysql_funcs[substr($text, 1, -1)]->new_name) {
|
||||
// strip quotes
|
||||
// move back because now 'some_mysql_func' will be returned by prev()
|
||||
$prev_steps = 1;
|
||||
$tmp_token = prev($this->tokens);
|
||||
|
||||
do {
|
||||
$tmp_token = prev($this->tokens);
|
||||
$prev_steps++;
|
||||
} while ($tmp_token[0] === T_WHITESPACE);
|
||||
|
||||
if ($tmp_token === '(') {
|
||||
|
||||
$tmp_token = prev($this->tokens);
|
||||
$prev_steps++;
|
||||
|
||||
if ($tmp_token[0] === T_STRING &&
|
||||
$tmp_token[1] === 'function_exists') {
|
||||
|
||||
$text = $text[0] . $this->mysql_funcs[substr($text, 1, -1)]->new_name . $text[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while ($prev_steps--)
|
||||
each($this->tokens);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($state) {
|
||||
case self::STATE_PARAM_LIST:
|
||||
|
||||
switch ($id) {
|
||||
|
||||
case T_VARIABLE:
|
||||
case T_FUNCTION:
|
||||
case T_CONST:
|
||||
// this is a variable, we cannot guess value of the parameter
|
||||
// using this static conversion approach
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
"Adding variable '$text' to current parameter."
|
||||
);
|
||||
}
|
||||
$param_dynamic = true;
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
|
||||
case T_WHITESPACE:
|
||||
default:
|
||||
if ($this->debug_dump_params) {
|
||||
$this->debug_print(
|
||||
'params',
|
||||
"Adding '$text' to current parameter."
|
||||
);
|
||||
}
|
||||
|
||||
$curr_param .= $text;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case self::STATE_FUNC_FOUND:
|
||||
|
||||
$this->errors[] = array('line' => $lineno, 'msg' => sprintf('[Line %d] Please check your code for parse errors, we failed to parse "%s". Conversion will be incomplete!".', $lineno, $text));
|
||||
break;
|
||||
|
||||
default:
|
||||
case self::STATE_NORMAL:
|
||||
$this->output .= $text;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print a debug message
|
||||
*
|
||||
* @param string Message prefix
|
||||
* @param mixed Array or literal to print
|
||||
*/
|
||||
protected function debug_print($prefix, $var) {
|
||||
|
||||
if (is_scalar($var)) {
|
||||
printf("[%s/%s] %s\n",
|
||||
get_class($this),
|
||||
$prefix,
|
||||
$var);
|
||||
} else {
|
||||
printf("[%s/%s] ", get_class($this), $prefix);
|
||||
var_dump($var);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
} // end func debug_print
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of lines of a string
|
||||
*
|
||||
* @param string
|
||||
* @return int
|
||||
*/
|
||||
protected function countLines($text) {
|
||||
|
||||
$last_pos = 0;
|
||||
$lines = 0;
|
||||
while (($pos = strpos($text, "\n", $last_pos)) !== FALSE) {
|
||||
$last_pos = $pos + 1;
|
||||
$lines++;
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rebuilds the original function code based on function name and parameters and adds a comment with a warning after the last parameter
|
||||
*
|
||||
* @param string
|
||||
* @param array
|
||||
* @param string
|
||||
*/
|
||||
protected function rebuildFunctionCode($name, $params, $warning) {
|
||||
|
||||
$ret = $name . '(';
|
||||
if (count($params) > 0) {
|
||||
foreach ($params as $k => $param)
|
||||
$ret .= $param['value'] . ', ';
|
||||
$ret = substr($ret, 0, -2);
|
||||
}
|
||||
$ret .= ')';
|
||||
// $ret .= ' /* [MySQLConverterTool] ' . $warning . '*/)';
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Expands a user specified file pattern with * as the only pattern to a regular expression
|
||||
*
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
protected function buildRegularExpression($file_pattern) {
|
||||
|
||||
$parts = explode(',', $file_pattern);
|
||||
if (empty($parts))
|
||||
return array();
|
||||
|
||||
$ret = array();
|
||||
foreach ($parts as $k => $v)
|
||||
$ret[] = str_replace('\*', '.*', preg_quote($v, '@'));
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,2 @@
|
|||
This is a Subversion working copy administrative directory.
|
||||
Visit http://subversion.tigris.org/ for more information.
|
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 67
|
||||
/svnpublic/mysqli_converter/!svn/ver/11/MySQLConverterTool/Function
|
||||
END
|
|
@ -0,0 +1,257 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<wc-entries
|
||||
xmlns="svn:">
|
||||
<entry
|
||||
committed-rev="11"
|
||||
name=""
|
||||
committed-date="2006-09-28T08:12:53.940894Z"
|
||||
url="http://svn.mysql.com/svnpublic/mysqli_converter/MySQLConverterTool/Function"
|
||||
last-author="uwendel"
|
||||
kind="dir"
|
||||
uuid="366cee77-c380-44c0-aa1c-990a1e0ff0dc"
|
||||
repos="http://svn.mysql.com/svnpublic/mysqli_converter"
|
||||
revision="11"/>
|
||||
<entry
|
||||
committed-rev="11"
|
||||
name="Error.php"
|
||||
text-time="2006-09-28T08:27:20.000000Z"
|
||||
committed-date="2006-09-28T08:12:53.940894Z"
|
||||
checksum="7ddadff1d3c84bbba4c53b477c850d20"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-28T08:27:20.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="Connect.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="e36f56aaa45764aa8b7dc8db018edddf"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="ConnParamBool.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="e1bebe0735da1370fdf20ae4bdaf0be0"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FieldTable.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="1ef89c4b55c23a3ec0f6316881ccb4c1"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="RealEscapeString.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="e92a42f04130cd65c52c41f694539c89"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FetchField.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="d00c943809c385ddd9384695c262726e"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FieldFlags.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="768ea0fbe16f696c56f04b1d2e84ecb9"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="8"
|
||||
name="ListFields.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:13:53.424139Z"
|
||||
checksum="a7e4967b79ddfa604850d2de7c02d849"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="ListProcesses.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="416a14a6859b915af889d8ed602ce706"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="ListDBs.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="f81cb82eaac0c47213de8d33c3789a5e"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="8"
|
||||
name="ListTables.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:13:53.424139Z"
|
||||
checksum="af433f71507d5ad6e1d4052f2d627f87"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="8"
|
||||
name="CreateDB.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:13:53.424139Z"
|
||||
checksum="55957c262ca6e5ade7e2eb7416776a56"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="8"
|
||||
name="DropDB.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:13:53.424139Z"
|
||||
checksum="6e9528c910b11729d50eda3758f7cf27"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:44.000000Z"/>
|
||||
<entry
|
||||
committed-rev="10"
|
||||
name="DBQuery.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:36:43.873259Z"
|
||||
checksum="a514f1e2b3aec158987ef88a5d0c425f"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="UnbufferedQuery.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="2de4a15990e7e6cb2afaacfc2c7ba073"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="8"
|
||||
name="Generic.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:13:53.424139Z"
|
||||
checksum="ff6d52d244c6dd29424a0419b6439253"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="GenericBoolean.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="ab0a17dbf6d4d2937b7e82e2a49c853d"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="ConnParam.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="154850c2e9a8b24896e8469a5d7b3468"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FreeResult.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="7570b6b0243db29ffee9c3286b4db586"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FieldLen.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="b8f93140fd0bd13023cea72af512f3fa"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="ParReversed.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="04c5689049ed3b3c0818e81f150a964d"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FieldName.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="687df5bb8b33951543e6db07e3ed34a1"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="ChangeUser.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="b6d675d76aa5e35831bdf541c6b6604d"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="FieldType.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="8cbad9e405614b9ff4755a3218d0244b"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="8"
|
||||
name="SelectDB.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-28T16:13:53.424139Z"
|
||||
checksum="7fee09265f4e518f6771d822c22f5fd1"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="EscapeString.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="fa4b778969c3760a2d6740867ca93722"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
<entry
|
||||
committed-rev="3"
|
||||
name="Tablename.php"
|
||||
text-time="2006-09-07T02:43:45.000000Z"
|
||||
committed-date="2006-08-21T09:45:42.863852Z"
|
||||
checksum="6346bad8b11d44f5a085a5948259a077"
|
||||
last-author="uwendel"
|
||||
kind="file"
|
||||
prop-time="2006-09-07T02:43:45.000000Z"/>
|
||||
</wc-entries>
|
|
@ -0,0 +1 @@
|
|||
4
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_change_user
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_ChangeUser extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
public $new_name = 'mysqli_change_user';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// mysql_change_user ( string user, string password [, string database [, resource link_identifier]] )
|
||||
// mysqli_change_user ( mysqli link, string user, string password, string database )
|
||||
|
||||
$warning = NULL;
|
||||
|
||||
if (4 == count($params)) {
|
||||
|
||||
list($user, $pass, $db, $conn) = $this->extractParamValues($params);
|
||||
$ret = "mysqli_change_user($conn, $user, $pass, $db)";
|
||||
|
||||
} else if (3 == count($params)) {
|
||||
|
||||
list($user, $pass, $db) = $this->extractParamValues($params);
|
||||
$conn = $this->ston_name;
|
||||
$ret = "mysqli_change_user($conn, $user, $pass, $db)";
|
||||
|
||||
} else if (2 == count($params)) {
|
||||
|
||||
list($user, $pass) = $this->extractParamValues($params);
|
||||
$conn = $this->ston_name;
|
||||
|
||||
// [1] $res = mysqli_query(conn, 'SELECT DATABASE()')
|
||||
// [2] $row = mysqli_fetch_row($res);
|
||||
// [3] $row = array_shift($row);
|
||||
// [4] unset($row);
|
||||
// [5] mysqli_free_result($res);
|
||||
// [6] unset($res);
|
||||
// [7] mysqli_change_user(conn, user, pass, $db)
|
||||
//
|
||||
// [1] ( ($res = mysqli_query() ) ? $db : false
|
||||
// [2] ( ($res = mysqli_query() && row = mysqli_fetch_row($res)) ? $db : false
|
||||
// [3] ( ($res = mysqli_query() && row = mysqli_fetch_row($res) && ((row = array_shift(row)) !== false) ) ? true : false
|
||||
// [5] ( ($res = mysqli_query() && row = mysqli_fetch_row($res) && ((row = array_shift(row)) !== false) ) && mysqli_free_result(res) ) ? true : false
|
||||
// [7] ( ($res = mysqli_query() && row = mysqli_fetch_row($res) && ((row = array_shift(row)) !== false) ) && mysqli_free_result(res) ) ? mysqli_change_user(conn, user, pass, $row) : false
|
||||
|
||||
|
||||
$ret = '( ';
|
||||
$ret.= '( ';
|
||||
$ret.= '($___mysqli_res = mysqli_query(' . $conn . ', "SELECT DATABASE()")) && ';
|
||||
$ret.= '($___mysqli_tmp = mysqli_fetch_row($___mysqli_res)) && ';
|
||||
$ret.= '(($___mysqli_tmp = array_shift($___mysqli_tmp)) !== false) && ';
|
||||
$ret.= '(mysqli_free_result($___mysqli_res)) ';
|
||||
$ret.= ') ? ';
|
||||
$ret.= sprintf('mysqli_change_user(%s, %s, %s, $___mysqli_tmp) : ', $conn, $user, $pass);
|
||||
$ret.= 'false ';
|
||||
$ret.= ')';
|
||||
|
||||
} else {
|
||||
|
||||
$warning = self::PARSE_ERROR_WRONG_PARAMS;
|
||||
$ret = NULL;
|
||||
|
||||
}
|
||||
|
||||
return array($warning, $ret);
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'mysql_change_user() can be translated into mysqli_change_user if the database is given. If not, it must be emulated using mysqli_query() and SELECT DATABASE() - which looks a bit like a hack.';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: generic, mysql_func([resource]) -> mysqli_func(resource)
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_ConnParam extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
if (count($params) > 1)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($conn) = $this->extractParamValues($params);
|
||||
if (is_null($conn))
|
||||
$conn = $this->ston_name;
|
||||
|
||||
return array(NULL, "$this->new_name($conn)");
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Generic class for all functions that look like mysql_foo([<link_identifier>]) -> mysqli_bar(<link_identifier>)';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: generic, mysql_func([resource]) -> ((bool)mysqli_func(resource))
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_ConnParamBool extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
if (count($params) > 1)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($conn) = $this->extractParamValues($params);
|
||||
if (is_null($conn))
|
||||
$conn = $this->ston_name;
|
||||
|
||||
return array(NULL, '((is_null($___mysqli_res = ' . $this->new_name . '(' . $conn . '))) ? false : $___mysqli_res)');
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Generic class for all functions that look like mysql_foo([<link_identifier>]) -> ((bool)mysqli_bar(<link_identifier>))';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_connect, mysql_pconnect
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_Connect extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
public $new_name = 'mysqli_connect';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
static $last_params = array();
|
||||
|
||||
/*
|
||||
Known deficiencies:
|
||||
- will try to handle unix_socket but not the best solution
|
||||
*/
|
||||
|
||||
// mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )
|
||||
// mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]] )
|
||||
// mysqli_connect ( [string host [, string username [, string passwd [, string dbname [, int port [, string socket]]]]]] )
|
||||
|
||||
$warning = NULL;
|
||||
$socket = NULL;
|
||||
$port = NULL;
|
||||
|
||||
@list($server, $user, $password, $new_link, $client_flags) = $this->extractParamValues($params);
|
||||
if (!is_null($server)) {
|
||||
if ($params[0]['dynamic']) {
|
||||
$warning = 'Cannot analyze server parameter to extract host, socket and port! Conversion cannot be performed automatically. You must manually check the result of the conversion.';
|
||||
} else {
|
||||
list($server, $socket, $port) = $this->expandServerParam($server);
|
||||
}
|
||||
}
|
||||
|
||||
$found = false;
|
||||
if (is_null($new_link) || ($new_link == false)) {
|
||||
// Maybe someone relies on:
|
||||
// If a second call is made to mysql_connect() with the same arguments,
|
||||
// no new link will be established, but instead, the link identifier of the already
|
||||
// opened link will be returned. The new_link parameter modifies this behavior
|
||||
// and makes mysql_connect() always open a new link, even if mysql_connect()
|
||||
// was called before with the same parameters.
|
||||
// The current converter version cannot catch this. All we can do is throw a warning
|
||||
|
||||
foreach ($last_params as $k => $lparams) {
|
||||
if ($params == $lparams) {
|
||||
$warning .= " You're calling mysql_connect() twice with the same parameters. We don't know for sure if you want a new connection or reuse the old connection. You must check your code.";
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!$found)
|
||||
$last_params[] = $params;
|
||||
|
||||
|
||||
$dbname = 'NULL';
|
||||
$ret = NULL;
|
||||
$num_params = count($params);
|
||||
|
||||
if ($num_params < 5) {
|
||||
|
||||
if (!is_null($socket)) {
|
||||
|
||||
$ret = sprintf('(%s = %s(%s, %s, %s, %s, %d, \'%s\'))',
|
||||
$this->ston_name,
|
||||
$this->new_name,
|
||||
is_null($server) ? 'NULL' : $server,
|
||||
is_null($user) ? 'NULL' : $user,
|
||||
is_null($password) ? 'NULL' : $password,
|
||||
is_null($dbname) ? 'NULL' : $dbname,
|
||||
is_null($port) ? 'NULL' : $port,
|
||||
$socket);
|
||||
} else {
|
||||
|
||||
if (is_null($server)) {
|
||||
// mysql_connect()
|
||||
$ret = sprintf('(%s = %s())',
|
||||
$this->ston_name,
|
||||
$this->new_name);
|
||||
|
||||
} else if (!is_null($port)) {
|
||||
// port used - no chance to generate pretty code
|
||||
|
||||
$ret = sprintf('(%s = %s(%s, %s, %s, %s, %d))',
|
||||
$this->ston_name,
|
||||
$this->new_name,
|
||||
is_null($server) ? 'NULL' : $server,
|
||||
is_null($user) ? 'NULL' : $user,
|
||||
is_null($password) ? 'NULL' : $password,
|
||||
is_null($dbname) ? 'NULL' : $dbname,
|
||||
$port
|
||||
);
|
||||
|
||||
} else if (!is_null($password)) {
|
||||
|
||||
// mysql_connect(<server>, <username>, <password>)
|
||||
$ret = sprintf('(%s = %s(%s, %s, %s))',
|
||||
$this->ston_name,
|
||||
$this->new_name,
|
||||
is_null($server) ? 'NULL' : $server,
|
||||
is_null($user) ? 'NULL' : $user,
|
||||
$password);
|
||||
|
||||
} else if (!is_null($user)) {
|
||||
// mysql_connect(<server>, <username>
|
||||
$ret = sprintf('(%s = %s(%s, %s))',
|
||||
$this->ston_name,
|
||||
$this->new_name,
|
||||
is_null($server) ? 'NULL' : $server,
|
||||
$user);
|
||||
|
||||
} else {
|
||||
// mysql_connect(<server>) but not mysql_connect(<server:port>)
|
||||
|
||||
$ret = sprintf('(%s = %s(%s))',
|
||||
$this->ston_name,
|
||||
$this->new_name,
|
||||
$server);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if ($num_params == 5) {
|
||||
|
||||
$ret = sprintf('(((%s = mysqli_init()) && (mysqli_real_connect(%s, %s, %s, %s, %s, %d, %s, %s))) ? %s : FALSE)',
|
||||
$this->ston_name,
|
||||
$this->ston_name,
|
||||
$server,
|
||||
$user,
|
||||
$password,
|
||||
$dbname,
|
||||
is_null($port) ? 3306 : $port,
|
||||
is_null($socket) ? 'NULL' : $socket,
|
||||
$client_flags,
|
||||
$this->ston_name);
|
||||
|
||||
} else {
|
||||
// too many parameters
|
||||
|
||||
$warning = self::PARSE_ERROR_WRONG_PARAMS;
|
||||
$ret = NULL;
|
||||
|
||||
}
|
||||
|
||||
return array($warning, $ret);
|
||||
}
|
||||
|
||||
|
||||
protected function expandServerParam($server) {
|
||||
|
||||
$socket = NULL;
|
||||
$port = NULL;
|
||||
|
||||
$pos = strpos($server, ':/');
|
||||
if (FALSE !== $pos) {
|
||||
// Unix Socket
|
||||
|
||||
$first_ch = $server[0];
|
||||
$last_ch = substr($server, -1, 1);
|
||||
|
||||
if (($last_ch == '"' || $last_ch == "'") && $last_ch == $first_ch) {
|
||||
$server = substr($server, 1, -1);
|
||||
}
|
||||
|
||||
$socket = substr($server, $pos + 1);
|
||||
$server = '"localhost"';
|
||||
|
||||
} else if (preg_match('/(["\']*)([^:]+):(\d+)/iu', $server, $matches)) {
|
||||
// host:port
|
||||
|
||||
$server = $matches[1] . $matches[2] . $matches[1];
|
||||
$port = $matches[3];
|
||||
|
||||
}
|
||||
|
||||
return array($server, $socket, $port);
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'mysql_connect can be mapped to mysqli_connect with some parameter swapping if no client_flags are used. If client_flags are used, mysqli_init()/mysqli_real_connect() are needed.';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_create_db
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_CreateDB extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
// not used, but anyway
|
||||
public $new_name = 'mysqli_query';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// mysql_create_db ( string database_name [, resource link_identifier] )
|
||||
|
||||
if (count($params) < 1 || count($params) > 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($db, $conn) = $this->extractParamValues($params);
|
||||
if (is_null($conn))
|
||||
$conn = $this->ston_name;
|
||||
|
||||
list($db, $db_type) = $this->extractValueAndType(trim($db));
|
||||
|
||||
if ('const' == $db_type) {
|
||||
$ret = sprintf('((is_null($___mysqli_res = %s(%s, "CREATE DATABASE " . constant(\'%s\')))) ? false : $___mysqli_res)',
|
||||
$this->new_name,
|
||||
$conn,
|
||||
$db
|
||||
);
|
||||
} else {
|
||||
$ret = sprintf('((is_null($___mysqli_res = %s(%s, "CREATE DATABASE %s"))) ? false : $___mysqli_res)',
|
||||
$this->new_name,
|
||||
$conn,
|
||||
$db
|
||||
);
|
||||
}
|
||||
|
||||
return array('mysql_create_db(string database_name [...]) is emulated using mysqli_query() and CREATE DATABASE database_name. This is a possible SQL injection security bug as no tests are performed what value database_name has. Check your script!', $ret);
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_query and CREATE DATABASE.';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_db_query
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_DBQuery extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
public $new_name = 'mysqli_query';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// mysql_db_query ( string database, string query [, resource link_identifier] )
|
||||
if (count($params) < 2 || count($params) > 3)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($new_db, $query, $conn) = $this->extractParamValues($params);
|
||||
if (is_null($conn))
|
||||
$conn = $this->ston_name;
|
||||
|
||||
list($new_db, $new_db_type) = $this->extractValueAndType(trim($new_db));
|
||||
if ('const' == $new_db_type) {
|
||||
$ret = sprintf('((mysqli_query(%s, "USE " . constant(\'%s\'))) ? mysqli_query(%s, %s) : false)',
|
||||
$conn,
|
||||
$new_db,
|
||||
$conn,
|
||||
$query);
|
||||
} else {
|
||||
$ret = sprintf('((mysqli_query(%s, "USE %s")) ? mysqli_query(%s, %s) : false)',
|
||||
$conn,
|
||||
$new_db,
|
||||
$conn,
|
||||
$query);
|
||||
}
|
||||
|
||||
return array('mysql_db_query(string database_name [...]) is emulated using mysqli_query() and USE database_name. This is a possible SQL injection security bug as no tests are performed what value database_name has. Check your script!', $ret);
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_query and USE.';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_drop_db
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_DropDB extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
public $new_name = 'mysqli_query';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// mysql_drop_db ( string database_name [, resource link_identifier] )
|
||||
if (count($params) < 1 || count($params) > 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($db, $conn) = $this->extractParamValues($params);
|
||||
if (is_null($conn))
|
||||
$conn = $this->ston_name;
|
||||
|
||||
list($db, $db_type) = $this->extractValueAndType(trim($db));
|
||||
|
||||
if ('const' == $db_type) {
|
||||
$ret = sprintf('((is_null($___mysqli_res = %s(%s, "DROP DATABASE " . constant(\'%s\')))) ? false : $___mysqli_res)',
|
||||
$this->new_name,
|
||||
$conn,
|
||||
$db
|
||||
);
|
||||
} else {
|
||||
$ret = sprintf('((is_null($___mysqli_res = %s(%s, "DROP DATABASE %s"))) ? false : $___mysqli_res)',
|
||||
$this->new_name,
|
||||
$conn,
|
||||
$db
|
||||
);
|
||||
}
|
||||
|
||||
return array('mysql_drop_db(string database_name [...]) is emulated using mysqli_query() and DROP DATABASE database_name. This is a possible SQL injection security bug as no tests are performed what value database_name has. Check your script!', $ret);
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_query and DROP DATABASE.';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_error, mysql_errno
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
|
||||
class MySQLConverterTool_Function_Error extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
if (count($params) > 1)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($conn) = $this->extractParamValues($params);
|
||||
if (is_null($conn)) {
|
||||
$warning = 'mysql_error()/mysql_errno() can be called without a connection handle, mysqli_error()/mysqli_errno() not. As we do not know if a default connection has been opened, we have wrapped the function call in ((<if_default_conn_is_object>) ? mysqli_<func>(<default_conn>) : mysqli_connect_error()/mysqli_connect_errno()). This is not 100% the same as the original code in all cases. Check the generated code!';
|
||||
$conn = $this->ston_name;
|
||||
} else {
|
||||
$warning = null;
|
||||
}
|
||||
if ('mysqli_error' == $this->new_name)
|
||||
$ret = sprintf('((is_object(%s)) ? %s(%s) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))', $conn, $this->new_name, $conn);
|
||||
else
|
||||
$ret = sprintf('((is_object(%s)) ? %s(%s) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false))', $conn, $this->new_name, $conn);
|
||||
|
||||
return array($warning, $ret);
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'mysql_error()/mysql_errno() do not require a connection handle. When using the default connection for mysqli_error()/mysqli_errno() we throw a warning. We do not know for sure if a connection exists and add some extra code for the case it does not exist.';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_escape_string
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_EscapeString extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// mysql_escape_string ( string unescaped_string )
|
||||
|
||||
if (count($params) != 1)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
list($par1) = $this->extractParamValues($params);
|
||||
$conn = $this->ston_name;
|
||||
|
||||
$warning = 'WARNING: mysql_escape_string() is deprecated. If no global connection has been opened already the converter cannot use mysqli_real_escape_string() to emulate the function. We add a runtime test if a connection exists, if not trigger_error() gets used to throw an E_USER_ERROR. It would be a security bug to do anything else. You must fix our code manually!';
|
||||
$ret = sprintf('((isset(%s) && is_object(%s)) ? %s(%s, %s) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""))',
|
||||
$conn,
|
||||
$conn,
|
||||
$this->new_name,
|
||||
$conn,
|
||||
$par1
|
||||
);
|
||||
|
||||
return array($warning, $ret);
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_real_escape_string and the default connection. If not default connection exists an E_USER_ERROR gets thrown.';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_fetch_field
|
||||
*
|
||||
* NOTE: generates very ugly code, very difficult to emulate, rewrite your ext/mysql code...
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FetchField extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
public $new_name = "mysqli_fetch_field_direct";
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// object mysql_fetch_field ( resource result [, int field_offset] )
|
||||
// object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr )
|
||||
|
||||
if (count($params) < 1 || count($params) > 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
@list($res, $offset) = $this->extractParamValues($params);
|
||||
|
||||
|
||||
/*
|
||||
[01] $f = f() && is_object($f)
|
||||
[02] $f->primary_key = ($f->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0
|
||||
[03] $f->multiple_key = ($f->flags & MYSQLI_MULTIPLE_KEY_FLAG) ? 1 : 0
|
||||
[04] $f->unique_key = ($f->flags & MYSQLI_UNIQUE_KEY_FLAG) ? 1 : 0
|
||||
|
||||
MySQL source! #define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR || (t) == FIELD_TYPE_NEWDECIMAL)
|
||||
[05] $f->numeric = ($f->type <= MYSQLI_TYPE_INT24 || $f->fype == MYSQLI_TYPE_YEAR || ((defined('MYSQLI_TYPE_NEWDECIMAL')) ? ($f->type == MYSQLI_TYPE_NEWDECIMAL) : false)
|
||||
|
||||
[06] $f->blob = (int)in_array($f->type, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB))
|
||||
|
||||
[07] $f->unsinged = ($f->flags & MYSQLI_UNSIGNED_FLAG) ? 1 : 0
|
||||
[08] $f->zerofill = ($f->flags & MYSQLI_ZEROFILL_FLAG) ? 1 : 0
|
||||
|
||||
[09] $type = $f->type
|
||||
[10] $f->type = (($type == MYSQLI_TYPE_STRING) || ($type == MYSQLI_TYPE_VAR_STRING)) ? 'type' : ''
|
||||
[11] $f->type = ("" == $f-type && in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24))) ? "int " : ""
|
||||
[12] $f->type = ("" == $f-type && in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, ((defined("MYSQLI_TYPE_NEWDECIMAL")) ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)))) ? "real " : ""
|
||||
[13] $f->type = ("" == $f-type && $___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP) ? "timestamp " : ""
|
||||
[14] $f->type = ("" == $f-type && $___mysqli_tmp == MYSQLI_TYPE_YEAR) ? "year " : ""
|
||||
[15] $f->type = ("" == $f-type && ($___mysqli_tmp == MYSQLI_TYPE_DATE) || ($___mysqli_tmp == MYSQLI_TYPE_NEWDATE)) ? "date " : ""
|
||||
[16] $f->type = ("" == $f-type && $___mysqli_tmp == MYSQLI_TYPE_TIME) ? "time " : ""
|
||||
[17] $f->type = ("" == $f-type && $___mysqli_tmp == MYSQLI_TYPE_SET) ? "set " : ""
|
||||
[18] $f->type = ("" == $f-type && ($___mysqli_tmp == MYSQLI_TYPE_ENUM) ? "enum " : ""
|
||||
[19] $f->type = ("" == $f-type && ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY) ? "geometry " : ""
|
||||
[20] $f->type = ("" == $f-type && ($___mysqli_tmp == MYSQLI_TYPE_DATETIME) ? "datetime " : ""
|
||||
[21] $f->type = ("" == $f-type && (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB))) ? "blob " : ""
|
||||
[22] $f->type = ("" == $f-type && ($___mysqli_tmp == MYSQLI_TYPE_NULL) ? "null " : "unknown";
|
||||
|
||||
[23] $f->not_null = ($f->flags & MYSQLI_NOT_NULL_FLAG) ? 1 : 0
|
||||
|
||||
(
|
||||
([01] && is_object($f) ? (
|
||||
!is_null([02]) && !is_null([03]) && !is_null([04]) &&
|
||||
!is_null([05]) && !is_null([06]) && !is_null([07]) &&
|
||||
!is_null([08]) && !is_null([09]) ...
|
||||
) : false) ? $___mysqli_tmp : false)
|
||||
*/
|
||||
|
||||
$warning = 'You should rewrite all your mysql_fetch_field() calls. The generated code should be compatible. But have a look at the generated code, it is unmaintainable! FIX your code!';
|
||||
|
||||
|
||||
$ret = '(';
|
||||
$ret.= '(';
|
||||
// [01]
|
||||
$ret.= sprintf('(($___mysqli_tmp = mysqli_fetch_field_direct(%s, %s)) && is_object($___mysqli_tmp))', $res,
|
||||
(is_null($offset)) ? sprintf('mysqli_field_tell(%s)', $res) : (int)$offset);
|
||||
$ret.= ' ? ( ';
|
||||
// [02]
|
||||
$ret.= '(!is_null($___mysqli_tmp->primary_key = ($___mysqli_tmp->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0)) && ';
|
||||
// [03]
|
||||
$ret.= '(!is_null($___mysqli_tmp->multiple_key = ($___mysqli_tmp->flags & MYSQLI_MULTIPLE_KEY_FLAG) ? 1 : 0)) && ';
|
||||
// [04]
|
||||
$ret.= '(!is_null($___mysqli_tmp->unique_key = ($___mysqli_tmp->flags & MYSQLI_UNIQUE_KEY_FLAG) ? 1 : 0)) && ';
|
||||
// [05]
|
||||
$ret.= '(!is_null($___mysqli_tmp->numeric = (int)(($___mysqli_tmp->type <= MYSQLI_TYPE_INT24) || ($___mysqli_tmp->type == MYSQLI_TYPE_YEAR) || ((defined("MYSQLI_TYPE_NEWDECIMAL")) ? ($___mysqli_tmp->type == MYSQLI_TYPE_NEWDECIMAL) : 0)))) && ';
|
||||
// [06]
|
||||
$ret.= '(!is_null($___mysqli_tmp->blob = (int)in_array($___mysqli_tmp->type, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)))) && ';
|
||||
// [07]
|
||||
$ret.= '(!is_null($___mysqli_tmp->unsigned = ($___mysqli_tmp->flags & MYSQLI_UNSIGNED_FLAG) ? 1 : 0)) && ';
|
||||
// [08]
|
||||
$ret.= '(!is_null($___mysqli_tmp->zerofill = ($___mysqli_tmp->flags & MYSQLI_ZEROFILL_FLAG) ? 1 : 0)) && ';
|
||||
// [09]
|
||||
$ret.= '(!is_null($___mysqli_type = $___mysqli_tmp->type)) && ';
|
||||
// [10]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = (($___mysqli_type == MYSQLI_TYPE_STRING) || ($___mysqli_type == MYSQLI_TYPE_VAR_STRING)) ? "type" : "")) &&';
|
||||
// [11]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && in_array($___mysqli_type, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24))) ? "int" : $___mysqli_tmp->type)) &&';
|
||||
// [12]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && in_array($___mysqli_type, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, ((defined("MYSQLI_TYPE_NEWDECIMAL")) ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)))) ? "real" : $___mysqli_tmp->type)) && ';
|
||||
// [13]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_TIMESTAMP) ? "timestamp" : $___mysqli_tmp->type)) && ';
|
||||
// [14]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_YEAR) ? "year" : $___mysqli_tmp->type)) && ';
|
||||
// [15]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && (($___mysqli_type == MYSQLI_TYPE_DATE) || ($___mysqli_type == MYSQLI_TYPE_NEWDATE))) ? "date " : $___mysqli_tmp->type)) && ';
|
||||
// [16]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_TIME) ? "time" : $___mysqli_tmp->type)) && ';
|
||||
// [17]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_SET) ? "set" : $___mysqli_tmp->type)) &&';
|
||||
// [18]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_ENUM) ? "enum" : $___mysqli_tmp->type)) && ';
|
||||
// [19]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_GEOMETRY) ? "geometry" : $___mysqli_tmp->type)) && ';
|
||||
// [20]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_DATETIME) ? "datetime" : $___mysqli_tmp->type)) && ';
|
||||
// [21]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && (in_array($___mysqli_type, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB)))) ? "blob" : $___mysqli_tmp->type)) && ';
|
||||
// [22]
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type && $___mysqli_type == MYSQLI_TYPE_NULL) ? "null" : $___mysqli_tmp->type)) && ';
|
||||
$ret.= '(!is_null($___mysqli_tmp->type = ("" == $___mysqli_tmp->type) ? "unknown" : $___mysqli_tmp->type)) && ';
|
||||
// [23]
|
||||
$ret.= '(!is_null($___mysqli_tmp->not_null = ($___mysqli_tmp->flags & MYSQLI_NOT_NULL_FLAG) ? 1 : 0))';
|
||||
|
||||
$ret.= ' ) : false';
|
||||
$ret.= ' )';
|
||||
$ret.= ' ? $___mysqli_tmp : false)';
|
||||
|
||||
|
||||
return array($warning, $ret);
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_fetch_field_direct() and a conditional expression.';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_field_flags()
|
||||
*
|
||||
* Generates ugly code, rewrite the ext/mysql code
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FieldFlags extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
public $new_name = 'mysqli_fetch_field_direct';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// string mysql_field_flags ( resource result, int field_offset )
|
||||
// "not_null" NOT_NULL_FLAG MYSQLI_NOT_NULL_FLAG
|
||||
// "primary_key" PRI_KEY_FLAG MYSQLI_PRI_KEY_FLAG
|
||||
// "unique_key" UNIQUE_KEY_FLAG MYSQLI_UNIQUE_KEY_FLAG
|
||||
// "multiple_key" MULTIPLE_KEY_FLAG MYSQLI_MULTIPLE_KEY_FLAG
|
||||
// "blob" BLOB_FLAG MYSQLI_BLOB_FLAG
|
||||
// "unsigned" UNSIGNED_FLAG MYSQLI_UNSIGNED_FLAG
|
||||
// "zerofill" ZEROFILL_FLAG MYSQLI_ZEROFILL_FLAG
|
||||
// "binary" BINARY_FLAG !!!
|
||||
// "enum" ENUM_FLAG !!!
|
||||
// "auto_increment" AUTO_INCREMENT_FLAG MYSQLI_AUTO_INCREMENT_FLAG
|
||||
// "timestamp" TIMESTAMP_FLAG MYSQLI_TIMESTAMP_FLAG
|
||||
// "set" SET_FLAG MYSQLI_SET_FLAG
|
||||
|
||||
// object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr )
|
||||
|
||||
if (count($params) != 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
list($res, $i) = $this->extractParamValues($params);
|
||||
|
||||
// (($__f = <fetch_field>) ? (string)((substr((($__f & FLAG_CONSTANT) ? 'flag_string' : '')) [. ()], -1)) : false)
|
||||
// ----------- 1 ---------- ------------------- n --------------------------------------------------- ------- 3 --
|
||||
|
||||
// ----------- 1 ----------
|
||||
$ret = sprintf('(($___mysqli_tmp = %s(%s, %s)->flags) ? ',
|
||||
$this->new_name,
|
||||
$res,
|
||||
$i
|
||||
);
|
||||
|
||||
// ------------------- n ------------------------
|
||||
$ret .= '(string)(substr(';
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_NOT_NULL_FLAG) ? "not_null " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_PRI_KEY_FLAG) ? "primary_key " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_UNIQUE_KEY_FLAG) ? "unique_key " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_MULTIPLE_KEY_FLAG) ? "unique_key " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_BLOB_FLAG) ? "blob " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_UNSIGNED_FLAG) ? "unsigned " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_ZEROFILL_FLAG) ? "zerofill " : "") . ' ;
|
||||
// FIXME - Constants are missing in ext/mysqli, added to CVS on 20.07.2006
|
||||
$ret .= '(($___mysqli_tmp & 128) ? "binary " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & 256) ? "enum " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_AUTO_INCREMENT_FLAG) ? "auto_increment " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_TIMESTAMP_FLAG) ? "timestamp " : "") . ' ;
|
||||
$ret .= '(($___mysqli_tmp & MYSQLI_SET_FLAG) ? "set " : "")';
|
||||
$ret .= ', 0, -1)';
|
||||
|
||||
// ------- 3 --------------
|
||||
$ret .= ')';
|
||||
$ret .= ' : false)';
|
||||
|
||||
return array(NULL, $ret);
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_fetch_field_direct and a conditional espression.';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_field_len
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FieldLen extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
public $new_name = 'mysqli_fetch_fields';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// int mysql_field_len ( resource result, int field_offset )
|
||||
// array mysqli_fetch_fields ( mysqli_result result )
|
||||
if (count($params) != 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
list($res, $i) = $this->extractParamValues($params);
|
||||
|
||||
return array(NULL, sprintf('((($___mysqli_tmp = mysqli_fetch_fields(%s)) && (isset($___mysqli_tmp[%d]))) ? $___mysqli_tmp[%d]->length : false)',
|
||||
$res,
|
||||
$i,
|
||||
$i));
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_fetch_fields().';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_field_name
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FieldName extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
public $new_name = 'mysqli_fetch_field_direct';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// string mysql_field_name ( resource result, int field_offset )
|
||||
// mysqli_fetch_field_direct ( mysqli_result result, int fieldnr )
|
||||
|
||||
if (count($params) != 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
list($res, $i) = $this->extractParamValues($params);
|
||||
|
||||
return array(NULL, sprintf('((($___mysqli_tmp = mysqli_fetch_field_direct(%s, %d)->name) && (!is_null($___mysqli_tmp))) ? $___mysqli_tmp : false)', $res, $i));
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_fetch_field_direct().';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_field_table
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FieldTable extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
public $new_name = 'mysqli_fetch_field_direct';
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array())
|
||||
{
|
||||
// string mysql_field_table ( resource result, int field_offset )
|
||||
// object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr )
|
||||
|
||||
if (count($params) != 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
list($res, $i) = $this->extractParamValues($params);
|
||||
|
||||
return array(NULL, "(mysqli_fetch_field_direct($res, $i)->table)");
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_fetch_field_direct().';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_field_type
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FieldType extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
|
||||
public $new_name = 'mysqli_fetch_field_direct';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
function handle(Array $params = array()) {
|
||||
|
||||
// string mysql_field_type ( resource result, int field_offset )
|
||||
// object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr )
|
||||
|
||||
if (count($params) != 2)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
/*
|
||||
|
||||
The following types reported by ext/mysqli are not reported by ext/mysql:
|
||||
|
||||
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_CHAR", FIELD_TYPE_CHAR, CONST_CS | CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INTERVAL", FIELD_TYPE_INTERVAL, CONST_CS | CONST_PERSISTENT);
|
||||
#if MYSQL_VERSION_ID > 50002
|
||||
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BIT", FIELD_TYPE_BIT, CONST_CS | CONST_PERSISTENT);
|
||||
#endif
|
||||
*/
|
||||
list($res, $i) = $this->extractParamValues($params);
|
||||
|
||||
// (($__f = <fetch_field>->type) ? (string)((substr((($__f == FLAG_CONSTANT) ? 'flag_string' : '')) [. ()], -1) : false)
|
||||
// (($__f = <fetch_field>->type) ? (string)((substr((( ($__f == FLAG_CONSTANT) || (...) ) ? 'flag_string ' : '')) [. ()], -1) : false)
|
||||
// ----------- 1 ---------- ------------------- n ------------------------ ------- 3 --------------
|
||||
// refinement of 1:
|
||||
// ((is_object($__f = <fetch_field>) && !is_null($__f = $f__->type)) ?
|
||||
// refinement of n:
|
||||
// ((($__f == substr()) == "") ? "unknown" : $__f)
|
||||
|
||||
// ----------- 1 ----------
|
||||
$ret = '(';
|
||||
$ret.= sprintf('(is_object($___mysqli_tmp = mysqli_fetch_field_direct(%s, %d)) && !is_null($___mysqli_tmp = $___mysqli_tmp->type)) ? ', $res, $i);
|
||||
|
||||
// ------------------- n ------------------------
|
||||
$ret.= '((($___mysqli_tmp = ';
|
||||
$ret.= '(string)(substr(';
|
||||
$ret.= '( (($___mysqli_tmp == MYSQLI_TYPE_STRING) || ($___mysqli_tmp == MYSQLI_TYPE_VAR_STRING) ) ? "string " : "" ) . ';
|
||||
$ret.= '( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY, MYSQLI_TYPE_SHORT, MYSQLI_TYPE_LONG, MYSQLI_TYPE_LONGLONG, MYSQLI_TYPE_INT24))) ? "int " : "" ) . ';
|
||||
$ret.= '( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, ((defined("MYSQLI_TYPE_NEWDECIMAL")) ? constant("MYSQLI_TYPE_NEWDECIMAL") : -1)))) ? "real " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_TIMESTAMP) ? "timestamp " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_YEAR) ? "year " : "" ) . ';
|
||||
$ret.= '( (($___mysqli_tmp == MYSQLI_TYPE_DATE) || ($___mysqli_tmp == MYSQLI_TYPE_NEWDATE) ) ? "date " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_TIME) ? "time " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_SET) ? "set " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_ENUM) ? "enum " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_GEOMETRY) ? "geometry " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_DATETIME) ? "datetime " : "" ) . ';
|
||||
$ret.= '( (in_array($___mysqli_tmp, array(MYSQLI_TYPE_TINY_BLOB, MYSQLI_TYPE_BLOB, MYSQLI_TYPE_MEDIUM_BLOB, MYSQLI_TYPE_LONG_BLOB))) ? "blob " : "" ) . ';
|
||||
$ret.= '( ($___mysqli_tmp == MYSQLI_TYPE_NULL) ? "null " : "" )';
|
||||
$ret.= ', 0, -1))';
|
||||
$ret.= ') == "") ? "unknown" : $___mysqli_tmp)';
|
||||
|
||||
// ------- 3 --------------
|
||||
$ret.= ' : false)';
|
||||
|
||||
return array(NULL, $ret);
|
||||
}
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using mysqli_fetch_field_direct() and a conditional expression. The following types reported by ext/mysqli are not reposted by ext/mysql: MYSQLI_TYPE_CHAR, MYSQLI_TYPE_INTERVAL, MYSQLI_TYPE_BIT';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
require_once('Generic.php');
|
||||
|
||||
/**
|
||||
* Converter: mysql_free_result
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_FreeResult extends MySQLConverterTool_Function_Generic {
|
||||
|
||||
public $new_name = 'mysqli_free_result';
|
||||
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function handle(Array $params = array()) {
|
||||
|
||||
if (count($params) != 1)
|
||||
return array(self::PARSE_ERROR_WRONG_PARAMS, NULL);
|
||||
|
||||
list($res) = $this->extractParamValues($params);
|
||||
|
||||
return array(NULL, sprintf('((mysqli_free_result(%s) || (is_object(%s) && (get_class(%s) == "mysqli_result"))) ? true : false)', $res, $res, $res));
|
||||
}
|
||||
|
||||
|
||||
function getConversionHint() {
|
||||
|
||||
return 'Emulated using a conditional expression and mysqli_free_result().';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
/**
|
||||
* Converter: generic converter and base class for other converter functions
|
||||
*
|
||||
* @category Functions
|
||||
* @package MySQLConverterTool
|
||||
* @author Andrey Hristov <andrey@php.net>, Ulf Wendel <ulf.wendel@phpdoc.de>
|
||||
* @copyright 1997-2006 The PHP Group
|
||||
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
||||
* @version CVS: $Id:$, Release: @package_version@
|
||||
* @link http://www.mysql.com
|
||||
* @since Class available since Release 1.0
|
||||
*/
|
||||
class MySQLConverterTool_Function_Generic {
|
||||
|
||||
/**
|
||||
*
|
||||
* @const PARSE_ERROR_WRONG_PARAMS
|
||||
*/
|
||||
const PARSE_ERROR_WRONG_PARAMS = 'Wrong parameter count. Function call not converted, resulting code is incomplete -- original code used. You must check your source!';
|
||||
|
||||
|
||||
//
|
||||
// public
|
||||
//
|
||||
|
||||
/**
|
||||
* New name of the converted function
|
||||
*
|
||||
* Used only for functions that have MySQLi counterpart that takes the same
|
||||
* parameters as the originial MySQL extension function.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $new_name;
|
||||
|
||||
|
||||
/**
|
||||
* Name of a variable holding the connection identifier of all functions that rely on default connections
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ston_name = '$GLOBALS["___mysqli_ston"]';
|
||||
|
||||
|
||||
//
|
||||
// public
|
||||
//
|
||||
|
||||
public function __construct($new_name, $ston_name = NULL) {
|
||||
|
||||
$this->new_name = $new_name;
|
||||
if (!is_null($ston_name))
|
||||
$this->ston_name = $ston_name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Try to use less concats - dots - in the output string
|
||||
*
|
||||
* @param string
|
||||
* @param string
|
||||
*/
|
||||
public function smart_concat($par1, $par2) {
|
||||
|
||||
if ($par2[0] !== '"' && $par2[0] !== "'")
|
||||
return '"' . $par1 . '" . ' . $par2;
|
||||
|
||||
return $par2[0] . $par1 . substr($par2, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string with the functions call
|
||||
*
|
||||
* @param array list of parameters of the returned function call
|
||||
*/
|
||||
public function handle(Array $params = array()) {
|
||||
|
||||
$params = $this->extractParamValues($params);
|
||||
return array(NULL, $this->new_name."(".implode(", ", $params).")");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string which describes who the conversion is done
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConversionHint() {
|
||||
|
||||
return 'Using 1:1 counterpart from the MySQLi extension';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a PHP comment which describes how the conversion is done
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConversionPHPComment() {
|
||||
|
||||
$ret = wordwrap($this->getConversionHint(), 60);
|
||||
$ret = explode("\n", $ret);
|
||||
$ret = "\n// [MySQL->MySQLi] " . implode("\n// [MySQL->MySQLi] ", $ret);
|
||||
$ret .= "\n";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
//
|
||||
// protected
|
||||
//
|
||||
|
||||
/**
|
||||
* Extracts the parameter values from the parameter scanner hash
|
||||
*
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
protected function extractParamValues($params) {
|
||||
|
||||
$ret = array();
|
||||
foreach ($params as $k => $param) {
|
||||
$ret[] = $param['value'];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function extractValueAndType($var) {
|
||||
|
||||
$var_type = 'const';
|
||||
if ("" != $var && ($var[0] == '"' || $var[0] == "'") && $var[0] == substr($var, -1)) {
|
||||
$var = substr($var, 1, -1);
|
||||
$var_type = 'string_or_var';
|
||||
}
|
||||
if ("" != ($tmp = trim($var)) && $tmp[0] == '$') {
|
||||
$var_type = 'string_or_var';
|
||||
}
|
||||
|
||||
return array($var, $var_type);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue