├── .gitignore ├── docs └── images │ ├── mysqlconvert-file.png │ ├── mysqlconvert-home.png │ ├── mysqlconvert-snippet.png │ └── mysqlconvert-directory.png ├── SECURITY.md ├── index.php ├── GUI ├── snippets │ ├── footer.php │ ├── MySQLConverterTool_GUI_Snippets.php │ ├── show_converted_directory.php │ └── header.php ├── index.php ├── convert_snippet.php └── convert_file.php ├── UnitTests ├── Converter │ ├── TestCode │ │ ├── connect006.php │ │ ├── connect007.php │ │ ├── connect005.php │ │ ├── connect001.php │ │ ├── connect002.php │ │ ├── config.php │ │ ├── connect003.php │ │ ├── generic007.php │ │ ├── connect004.php │ │ ├── conn_param003.php │ │ ├── conn_param_bool003.php │ │ ├── conn_param_bool004.php │ │ ├── escape_string001.php │ │ ├── conn_param004.php │ │ ├── conn_param_bool002.php │ │ ├── conn_param007.php │ │ ├── conn_param005.php │ │ ├── field_len001.php │ │ ├── error002.php │ │ ├── error001.php │ │ ├── conn_param006.php │ │ ├── real_escape_string001.php │ │ ├── conn_param_bool001.php │ │ ├── field_table001.php │ │ ├── field_name001.php │ │ ├── generic_boolean002.php │ │ ├── conn_param001.php │ │ ├── conn_param002.php │ │ ├── tablename001.php │ │ ├── list_dbs001.php │ │ ├── conn_param008.php │ │ ├── generic008.php │ │ ├── generic_boolean001.php │ │ └── free_result001.php │ ├── DropDBTest.php │ ├── ChangeUserTest.php │ ├── DBQueryTest.php │ ├── ErrorTest.php │ ├── ListDBsTest.php │ ├── FreeResultTest.php │ ├── CreateDBTest.php │ ├── FieldLenTest.php │ ├── SelectDBTest.php │ ├── FieldNameTest.php │ ├── FieldTypeTest.php │ ├── TablenameTest.php │ ├── FetchFieldTest.php │ ├── FieldFlagsTest.php │ ├── FieldTableTest.php │ ├── ListFieldsTest.php │ ├── ParReversedTest.php │ ├── EscapeStringTest.php │ ├── ListProcessesTest.php │ ├── UnbufferedQueryTest.php │ ├── RealEscapeStringTest.php │ ├── GenericBooleanTest.php │ ├── ConnectTest.php │ ├── GenericTest.php │ ├── ConnParamBoolTest.php │ └── ConnParamTest.php ├── AllTests.php ├── Function │ ├── GenericBooleanTest.php │ ├── FetchFieldTest.php │ ├── EscapeStringTest.php │ ├── FreeResultTest.php │ ├── ListDBsTest.php │ ├── TablenameTest.php │ ├── ListProcessesTest.php │ ├── FieldTableTest.php │ ├── FieldLenTest.php │ ├── FieldNameTest.php │ ├── UnbufferedQueryTest.php │ ├── RealEscapeStringTest.php │ ├── ParReversedTest.php │ └── GenericTest.php └── README └── Function ├── GenericBoolean.php ├── ConnParam.php ├── Error.php ├── FreeResult.php ├── ConnParamBool.php ├── FieldTable.php ├── UnbufferedQuery.php ├── FieldName.php ├── ParReversed.php ├── FieldLen.php ├── ListProcesses.php ├── Tablename.php ├── ListDBs.php ├── SetCharset.php ├── SelectDB.php ├── RealEscapeString.php ├── Result.php ├── EscapeString.php ├── ListTables.php ├── DBQuery.php ├── DropDB.php ├── CreateDB.php └── ListFields.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.tmp 2 | *.bak 3 | *.log 4 | -------------------------------------------------------------------------------- /docs/images/mysqlconvert-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philip/MySQLConverterTool/HEAD/docs/images/mysqlconvert-file.png -------------------------------------------------------------------------------- /docs/images/mysqlconvert-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philip/MySQLConverterTool/HEAD/docs/images/mysqlconvert-home.png -------------------------------------------------------------------------------- /docs/images/mysqlconvert-snippet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philip/MySQLConverterTool/HEAD/docs/images/mysqlconvert-snippet.png -------------------------------------------------------------------------------- /docs/images/mysqlconvert-directory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philip/MySQLConverterTool/HEAD/docs/images/mysqlconvert-directory.png -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | This project is, essentially, abandoned. There is no real policy but security bugs will be taken seriously. 4 | 5 | ## Reporting a Vulnerability 6 | 7 | Write me; see contact information at github.com/philip 8 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * @version CVS: $Id:$, Release: @package_version@ 11 | * @link http://www.mysql.com 12 | * @since Available since Release 1.0 13 | */ 14 | header('Location: GUI/index.php'); 15 | exit(0); 16 | ?> -------------------------------------------------------------------------------- /GUI/snippets/footer.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Available since Release 1.0 15 | */ 16 | ?> 17 | 18 |
19 | Top 20 |
21 | 22 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/connect006.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_connect() with Unix Socket - ext/mysql reports success for bogus socket 3 | --FILE-- 4 | 11 | --EXPECT-EXT/MYSQL-OUTPUT-- 12 | bool(true) 13 | 14 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 15 | --EXPECT-EXT/MYSQLI-OUTPUT-- 16 | bool(false) 17 | 18 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 19 | --EXPECT-CONVERTER-ERRORS-- 20 | 6, 21 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/connect007.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_connect() with Unix Socket 3 | --FILE-- 4 | 11 | --EXPECT-EXT/MYSQL-OUTPUT-- 12 | bool(false) 13 | bool(false) 14 | 15 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 16 | --EXPECT-EXT/MYSQLI-OUTPUT-- 17 | bool(false) 18 | bool(false) 19 | 20 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 21 | 5, E_WARNING, mysqli_connect() 22 | 7, E_WARNING, mysqli_close() 23 | --EXPECT-CONVERTER-ERRORS-- 24 | 6, 25 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/connect005.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_connect with flags 3 | --FILE-- 4 | 16 | --EXPECT-EXT/MYSQL-OUTPUT-- 17 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 18 | --EXPECT-EXT/MYSQLI-OUTPUT-- 19 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 20 | --EXPECT-CONVERTER-ERRORS-- 21 | 5, 8, 11 22 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/connect001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: Simple mysql_connect(), static host, dynamic user, dynamic password 3 | --FILE-- 4 | 15 | --EXPECT-EXT/MYSQL-OUTPUT-- 16 | [connect_1] Success 17 | 18 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 19 | --EXPECT-EXT/MYSQLI-OUTPUT-- 20 | [connect_1] Success 21 | 22 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 23 | --EXPECT-CONVERTER-ERRORS-- 24 | 7, 7, 25 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/connect002.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: Simple mysql_connect - host, user, pass given, host with port 3 | --FILE-- 4 | 16 | --EXPECT-EXT/MYSQL-OUTPUT-- 17 | [connect_1] Success 18 | 19 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 20 | --EXPECT-EXT/MYSQLI-OUTPUT-- 21 | [connect_1] Success 22 | 23 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 24 | --EXPECT-CONVERTER-ERRORS-- 25 | 8, 8, 26 | --ENDOFTEST-- 27 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/config.php: -------------------------------------------------------------------------------- 1 | 17 | --EXPECT-EXT/MYSQL-OUTPUT-- 18 | [connect_1] Success 19 | 20 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 21 | --EXPECT-EXT/MYSQLI-OUTPUT-- 22 | [connect_1] Success 23 | 24 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 25 | --EXPECT-CONVERTER-ERRORS-- 26 | 7, 9, 9 27 | --ENDOFTEST-- -------------------------------------------------------------------------------- /Function/GenericBoolean.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_GenericBoolean extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | $params = $this->extractParamValues($params); 24 | 25 | return array(null, sprintf('(($___mysqli_tmp = %s(%s)) ? $___mysqli_tmp : false)', $this->new_name, implode(', ', $params))); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/generic007.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_get_client_info 3 | --FILE-- 4 | = 4.0.5, PHP 5) 9 | mysql_get_client_info -- Get MySQL client info 10 | Description 11 | string mysql_get_client_info ( void ) 12 | 13 | mysql_get_client_info() returns a string that represents the client library version. 14 | Return Values 15 | 16 | The MySQL client version. 17 | */ 18 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 19 | 20 | $client_info = mysql_get_client_info(); 21 | if (!is_string($client_info)) { 22 | printf("FAILURE: expected string value, got %s value\n", gettype($client_info)); 23 | } else { 24 | printf("SUCCESS\n"); 25 | } 26 | ?> 27 | --EXPECT-EXT/MYSQL-OUTPUT-- 28 | SUCCESS 29 | 30 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 31 | --EXPECT-EXT/MYSQLI-OUTPUT-- 32 | SUCCESS 33 | 34 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 35 | --EXPECT-CONVERTER-ERRORS-- 36 | --ENDOFTEST-- -------------------------------------------------------------------------------- /GUI/snippets/MySQLConverterTool_GUI_Snippets.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Class available since Release 1.0 15 | */ 16 | class MySQLConverterTool_GUI_Snippets 17 | { 18 | public static function load($___file) 19 | { 20 | if (!file_exists($___file)) { 21 | echo $___file; 22 | 23 | return false; 24 | } 25 | 26 | foreach ($GLOBALS as $___k => $___v) { 27 | if (substr($___k, 0, 8) == 'snippet_') { 28 | $$___k = $___v; 29 | } 30 | } 31 | 32 | include $___file; 33 | 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/connect004.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | FAILURE: Simple mysql_connect - host, user, pass given, new connection requested, relying on same connection for same params 3 | --FILE-- 4 | 21 | --EXPECT-EXT/MYSQL-OUTPUT-- 22 | SUCCESS: new connection created 23 | 24 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 25 | --EXPECT-EXT/MYSQLI-OUTPUT-- 26 | SUCCESS: new connection created 27 | 28 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 29 | --EXPECT-CONVERTER-ERRORS-- 30 | 5, 6, 16 31 | --ENDOFTEST-- -------------------------------------------------------------------------------- /Function/ConnParam.php: -------------------------------------------------------------------------------- 1 | mysqli_func(resource). 7 | * 8 | * @category Functions 9 | * 10 | * @author Andrey Hristov , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ConnParam extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | if (count($params) > 1) { 24 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 25 | } 26 | 27 | @list($conn) = $this->extractParamValues($params); 28 | if (is_null($conn)) { 29 | $conn = $this->ston_name; 30 | } 31 | 32 | return array(null, "$this->new_name($conn)"); 33 | } 34 | 35 | public function getConversionHint() 36 | { 37 | return 'Generic class for all functions that look like mysql_foo([]) -> mysqli_bar()'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Function/Error.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_Error extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | if (count($params) > 1) { 24 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 25 | } 26 | 27 | @list($conn) = $this->extractParamValues($params); 28 | if (is_null($conn)) { 29 | $conn = $this->ston_name; 30 | } 31 | 32 | return array(null, sprintf('%s(%s)', $this->new_name, $conn)); 33 | } 34 | 35 | public function getConversionHint() 36 | { 37 | 38 | return 'mysql_error()/mysql_errno() do not require a connection handle. A default connection has to be made before. '; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Function/FreeResult.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_FreeResult extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_free_result'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | if (count($params) != 1) { 30 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 31 | } 32 | 33 | list($res) = $this->extractParamValues($params); 34 | 35 | return array(null, sprintf('((mysqli_free_result(%s) || (is_object(%s) && (get_class(%s) == "mysqli_result"))) ? true : false)', $res, $res, $res)); 36 | } 37 | 38 | public function getConversionHint() 39 | { 40 | return 'Emulated using a conditional expression and mysqli_free_result().'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /UnitTests/AllTests.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 18 | * @copyright 1997-2006 The PHP Group 19 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 20 | * 21 | * @version CVS: $Id:$, Release: @package_version@ 22 | * 23 | * @link http://www.mysql.com 24 | * @since Class available since Release 1.0 25 | */ 26 | class AllTests 27 | { 28 | public static function main() 29 | { 30 | PHPUnit_TextUI_TestRunner::run(self::suite()); 31 | } 32 | 33 | public static function suite() 34 | { 35 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool'); 36 | $suite->addTest(MySQLConverterTool_UnitTests_Function_AllTests::suite()); 37 | $suite->addTest(MySQLConverterTool_UnitTests_Converter_AllTests::suite()); 38 | 39 | return $suite; 40 | } 41 | } 42 | 43 | if (PHPUnit_MAIN_METHOD == 'AllTests::main') { 44 | AllTests::main(); 45 | } 46 | -------------------------------------------------------------------------------- /Function/ConnParamBool.php: -------------------------------------------------------------------------------- 1 | ((bool)mysqli_func(resource)). 7 | * 8 | * @category Functions 9 | * 10 | * @author Andrey Hristov , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ConnParamBool extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | if (count($params) > 1) { 24 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 25 | } 26 | 27 | @list($conn) = $this->extractParamValues($params); 28 | if (is_null($conn)) { 29 | $conn = $this->ston_name; 30 | } 31 | 32 | return array(null, '((is_null($___mysqli_res = '.$this->new_name.'('.$conn.'))) ? false : $___mysqli_res)'); 33 | } 34 | 35 | public function getConversionHint() 36 | { 37 | return 'Generic class for all functions that look like mysql_foo([]) -> ((bool)mysqli_bar())'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Function/FieldTable.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_FieldTable extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_fetch_field_direct'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | // string mysql_field_table ( resource result, int field_offset ) 30 | // object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr ) 31 | 32 | if (count($params) != 2) { 33 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 34 | } 35 | 36 | list($res, $i) = $this->extractParamValues($params); 37 | 38 | return array(null, "(mysqli_fetch_field_direct($res, $i)->table)"); 39 | } 40 | 41 | public function getConversionHint() 42 | { 43 | return 'Emulated using mysqli_fetch_field_direct().'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Function/UnbufferedQuery.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_UnbufferedQuery extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_unbuffered_query ( string query [, resource link_identifier] ) 31 | if (count($params) < 1 || count($params) > 2) { 32 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 33 | } 34 | 35 | @list($q, $conn) = $this->extractParamValues($params); 36 | if (is_null($conn)) { 37 | $conn = $this->ston_name; 38 | } 39 | 40 | return array(null, "mysqli_query($conn, $q, MYSQLI_USE_RESULT)"); 41 | } 42 | 43 | public function getConversionHint() 44 | { 45 | return 'Emulated using mysqli_query and MYSQLI_USE_RESULT.'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Function/FieldName.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_FieldName extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_fetch_field_direct'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // string mysql_field_name ( resource result, int field_offset ) 31 | // mysqli_fetch_field_direct ( mysqli_result result, int fieldnr ) 32 | 33 | if (count($params) != 2) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | list($res, $i) = $this->extractParamValues($params); 38 | 39 | return array(null, sprintf('((($___mysqli_tmp = mysqli_fetch_field_direct(%s, %s)->name) && (!is_null($___mysqli_tmp))) ? $___mysqli_tmp : false)', $res, $i)); 40 | } 41 | 42 | public function getConversionHint() 43 | { 44 | return 'Emulated using mysqli_fetch_field_direct().'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Function/ParReversed.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ParReversed extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | 24 | // mysql_query ( string query [, resource link_identifier] ) 25 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 26 | 27 | if (count($params) < 1 || count($params) > 2) { 28 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 29 | } 30 | 31 | @list($par1, $conn) = $this->extractParamValues($params); 32 | if (is_null($conn)) { 33 | $conn = $this->ston_name; 34 | } 35 | 36 | return array(null, "$this->new_name($conn, $par1)"); 37 | } 38 | 39 | public function getConversionHint() 40 | { 41 | return 'Generic function for: mysql_func(param1, param2) => mysqli_func(param2, param1). Currently used for mysql_query(), mysql_real_escape_string()'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Function/FieldLen.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_FieldLen extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_fetch_fields'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // int mysql_field_len ( resource result, int field_offset ) 31 | // array mysqli_fetch_fields ( mysqli_result result ) 32 | if (count($params) != 2) { 33 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 34 | } 35 | 36 | list($res, $i) = $this->extractParamValues($params); 37 | 38 | return array(null, sprintf('((($___mysqli_tmp = mysqli_fetch_fields(%s)) && (isset($___mysqli_tmp[%d]))) ? $___mysqli_tmp[%d]->length : false)', 39 | $res, 40 | $i, 41 | $i)); 42 | } 43 | 44 | public function getConversionHint() 45 | { 46 | return 'Emulated using mysqli_fetch_fields().'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Function/ListProcesses.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ListProcesses extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // resource mysql_list_processes ( [resource link_identifier] ) 31 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 32 | 33 | if (count($params) > 1) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | @list($conn) = $this->extractParamValues($params); 38 | if (is_null($conn)) { 39 | $conn = $this->ston_name; 40 | } 41 | 42 | return array(null, sprintf('mysqli_query(%s, "SHOW PROCESSLIST")', $conn)); 43 | } 44 | 45 | public function getConversionHint() 46 | { 47 | return 'Emulated using mysqli_query() and SHOW PROCESSLIST.'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Function/Tablename.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_Tablename extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_fetch_row'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_db_name ( resource result, int row [, mixed field] ) 31 | // string mysql_tablename ( resource result, int i ) 32 | 33 | if (count($params) != 2) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | list($res, $i) = $this->extractParamValues($params); 38 | 39 | return array(null, sprintf('((mysqli_data_seek(%s, %s) && (($___mysqli_tmp = mysqli_fetch_row(%s)) !== NULL)) ? array_shift($___mysqli_tmp) : false)', $res, $i, $res)); 40 | } 41 | 42 | public function getConversionHint() 43 | { 44 | return 'Emulated using mysqli_data_seek(), mysqli_fetch_row() and a conditional expression.'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Function/ListDBs.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ListDBs extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_list_dbs ( [resource link_identifier] ) 31 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 32 | if (count($params) > 1) { 33 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 34 | } 35 | 36 | @list($conn) = $this->extractParamValues($params); 37 | if (is_null($conn)) { 38 | $conn = $this->ston_name; 39 | } 40 | 41 | return array(null, sprintf('(($___mysqli_tmp = mysqli_query(%s, "SHOW DATABASES")) ? $___mysqli_tmp : false)', $conn)); 42 | } 43 | 44 | public function getConversionHint() 45 | { 46 | return 'Emulated using mysqli_query() and SHOW DATABASES. Returns NULL instead of false in case of an error'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Function/SetCharset.php: -------------------------------------------------------------------------------- 1 | 11 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 12 | */ 13 | class MySQLConverterTool_Function_SetCharset extends MySQLConverterTool_Function_Generic 14 | { 15 | public $new_name = 'mysqli_set_charset'; 16 | 17 | public function __construct() 18 | { 19 | } 20 | 21 | public function handle(array $params = array()) 22 | { 23 | 24 | // bool mysql_select_db ( string database_name [, resource link_identifier] ) 25 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 26 | 27 | if (count($params) < 1 || count($params) > 2) { 28 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 29 | } 30 | 31 | @list($charset, $conn) = $this->extractParamValues($params); 32 | if (is_null($conn)) { 33 | $conn = $this->ston_name; 34 | } 35 | 36 | list($charset, $charset_type) = $this->extractValueAndType(trim($charset)); 37 | if ('const' == $charset_type) { 38 | $ret = sprintf('((bool)mysqli_set_charset(%s, constant(\'%s\')))', $conn, $charset); 39 | } else { 40 | $ret = sprintf('((bool)mysqli_set_charset(%s, "%s"))', $conn, $charset); 41 | } 42 | 43 | return array(null, $ret); 44 | } 45 | 46 | public function getConversionHint() 47 | { 48 | return 'Direct mapping to mysqli_set_charset with swapping parameters.'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Function/SelectDB.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_SelectDB extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_select_db'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // bool mysql_select_db ( string database_name [, resource link_identifier] ) 31 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 32 | 33 | if (count($params) < 1 || count($params) > 2) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | @list($db, $conn) = $this->extractParamValues($params); 38 | if (is_null($conn)) { 39 | $conn = $this->ston_name; 40 | } 41 | 42 | list($db, $db_type) = $this->extractValueAndType(trim($db)); 43 | if ('const' == $db_type) { 44 | $ret = sprintf('mysqli_select_db(%s, constant(\'%s\'))', $conn, $db); 45 | } else { 46 | $ret = sprintf('mysqli_select_db(%s, %s)', $conn, $db); 47 | } 48 | 49 | return array('', $ret); 50 | } 51 | 52 | public function getConversionHint() 53 | { 54 | return 'Converted to mysqli_select_db().'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Function/RealEscapeString.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_RealEscapeString extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | 24 | // string mysql_real_escape_string ( string unescaped_string [, resource link_identifier] ) 25 | // string mysqli_real_escape_string ( mysqli link, string escapestr ) 26 | 27 | if (count($params) == 1) { 28 | list($string) = $this->extractParamValues($params); 29 | $conn = $this->ston_name; 30 | $warning = null; 31 | $ret = sprintf('%s(%s, %s)', $this->new_name, $conn, $string); 32 | 33 | } else if (count($params) == 2) { 34 | 35 | list($string, $conn) = @$this->extractParamValues($params); 36 | $warning = null; 37 | $ret = sprintf('%s(%s, %s)', $this->new_name, $conn, $string); 38 | } else { 39 | $warning = self::PARSE_ERROR_WRONG_PARAMS; 40 | $ret = null; 41 | } 42 | 43 | return array($warning, $ret); 44 | } 45 | 46 | function getConversionHint() { 47 | 48 | return 'Emulated using mysqli_real_escape_string and the default connection if no connection is given. A default connection has to be made before.'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Function/Result.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class MySQLConverterTool_Function_Result extends MySQLConverterTool_Function_Generic 13 | { 14 | public $new_name = 'mysqli_result'; 15 | 16 | public function __construct() 17 | { 18 | } 19 | 20 | public function handle(array $params = array()) 21 | { 22 | $pcount = count($params); 23 | 24 | if ($pcount != 2 && $pcount != 3) { 25 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 26 | } 27 | 28 | if ($pcount === 3) { 29 | list($res, $row, $field) = $this->extractParamValues($params); 30 | $warning = $this->getConversionHint(); 31 | 32 | return array($warning, sprintf('mysqli_result(%s, %s, %s)', $res, $row, $field)); 33 | } 34 | 35 | if ($pcount === 2) { 36 | list($res, $row) = $this->extractParamValues($params); 37 | $warning = $this->getConversionHint(); 38 | 39 | return array($warning, sprintf('mysqli_result(%s, %s)', $res, $row)); 40 | } 41 | } 42 | 43 | public function getConversionHint() 44 | { 45 | return 'Emulated by creating mysqli_result(). YOU must manually add a mysqli_result() definition to your code, such as: 46 | 47 | function mysqli_result($result, $number, $field=0) { 48 | mysqli_data_seek($result, $number); 49 | $type = is_numeric($field) ? MYSQLI_NUM : MYSQLI_ASSOC; 50 | $out = mysqli_fetch_array($result, $type); 51 | if ($out === NULL || $out === FALSE || (!isset($out[$field]))) { 52 | return FALSE; 53 | } 54 | return $out[$field]; 55 | } 56 | '; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /GUI/index.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Available since Release 1.0 15 | */ 16 | require_once 'snippets/MySQLConverterTool_GUI_Snippets.php'; 17 | 18 | $snippet_title = 'Welcome to the MySQL ext/mysql Converter Tool'; 19 | $snippet_greeting = 'Welcome to the MySQL ext/mysql Converter Tool'; 20 | 21 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/header.php'); 22 | ?> 23 |
24 | You have successfully installed the MySQL ext/mysql Converter Tool. 25 | The tool helps you to migrate existing PHP code using the PHP MySQL Extension 26 | (ext/mysql) to the PHP MySQLi Extension (ext/mysqli). The tool reads the source code 27 | and converts all MySQL functions into their MySQLi counterparts. 28 |
29 |
30 | Select one of the following actions: 31 |
32 |
33 |

Convert a directory

34 | Use this to convert all PHP files contained in one 35 | directory. 36 |
37 |
38 |

Convert a file

39 | Use this to convert a single PHP file. 40 |
41 |
42 |

Convert a code snippet

43 | Use this to convert a snippet, a piece of PHP code. 44 |
45 | -------------------------------------------------------------------------------- /UnitTests/Function/GenericBooleanTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 15 | * @copyright 1997-2006 The PHP Group 16 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 17 | * 18 | * @version CVS: $Id:$, Release: @package_version@ 19 | * 20 | * @link http://www.mysql.com 21 | * @since Class available since Release 1.0 22 | */ 23 | class MySQLConverterTool_UnitTests_Function_GenericBooleanTest extends MySQLConverterTool_UnitTests_Function_GenericTest 24 | { 25 | protected $default_conn = null; 26 | protected $gen = null; 27 | 28 | public static function main() 29 | { 30 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_Function_GenericBooleanTest'); 31 | $result = PHPUnit_TextUI_TestRunner::run($suite); 32 | } 33 | 34 | protected function setUp() 35 | { 36 | $this->gen = new MySQLConverterTool_Function_GenericBoolean('mysqli_fetch_length'); 37 | $this->default_conn = $this->gen->ston_name; 38 | } 39 | 40 | public function testHandle() 41 | { 42 | list($warning, $code) = $this->gen->handle($this->buildParams(array('A', 'B'))); 43 | $this->assertNull($warning); 44 | $this->assertEquals('(($___mysqli_tmp = mysqli_fetch_length(A, B)) ? $___mysqli_tmp : false)', $code); 45 | } 46 | } 47 | 48 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_GenericBooleanTest::main') { 49 | MySQLConverterTool_Function_GenericBooleanTest::main(); 50 | } 51 | -------------------------------------------------------------------------------- /GUI/snippets/show_converted_directory.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Available since Release 1.0 15 | */ 16 | ?> 17 |
18 |

Results of the conversion

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
Number of FilesOKWarningsErrorsNumber of mysql_*-functions foundNumber of mysql_*-functions convertedCode (kB)
0) ? $snippet_conv_length / 1024 : 0); ?>
39 |
-------------------------------------------------------------------------------- /UnitTests/Converter/DropDBTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_DropDBTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('drop_db001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_DropDBTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_DropDBTest::main') { 50 | MySQLConverterTool_DropDBTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/ChangeUserTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ChangeUserTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('change_user001.php'); 29 | 30 | foreach ($files as $k => $file) { 31 | $file = dirname(__FILE__).'/TestCode/'.$file; 32 | $test_spec = $this->parseTestFile($file); 33 | if ($err = $this->validateTestSpec($test_spec)) { 34 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 35 | 36 | return; 37 | } 38 | if ($err = $this->runTestSpec($test_spec)) { 39 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 40 | 41 | return; 42 | }; 43 | } 44 | } 45 | } 46 | 47 | // Call MySQLConverterTool_ChangeUserTest::main() if this source file is executed directly. 48 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ChangeUserTest::main') { 49 | MySQLConverterTool_ChangeUserTest::main(); 50 | } 51 | -------------------------------------------------------------------------------- /UnitTests/Converter/DBQueryTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_DBQueryTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('db_query001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_DBQueryTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_DBQueryTest::main') { 50 | MySQLConverterTool_DBQueryTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/ErrorTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ErrorTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('error001.php', 'error002.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_ErrorTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ErrorTest::main') { 50 | MySQLConverterTool_ErrorTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/ListDBsTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ListDBsTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('list_dbs001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_ListDBsTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ListDBsTest::main') { 50 | MySQLConverterTool_ListDBsTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param003.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_client_encoding() 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_client_encoding -- Returns the name of the character set 10 | Description 11 | string mysql_client_encoding ( [resource link_identifier] ) 12 | 13 | Retrieves the character_set variable from MySQL. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns the default character set name for the current connection. 23 | */ 24 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 25 | 26 | $con = mysql_connect($host, $user, $pass); 27 | if (!$con) { 28 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 29 | } else { 30 | echo "SUCCESS: connect\n"; 31 | } 32 | 33 | if (!mysql_select_db($db, $con)) { 34 | printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con)); 35 | } 36 | 37 | $encoding_default = mysql_client_encoding(); 38 | $encoding_con = mysql_client_encoding($con); 39 | 40 | if ($encoding_con != $encoding_default) { 41 | printf("FAILURE: different client encodings reported, [%d] %s\n", mysql_errno($con), mysql_error($con)); 42 | } elseif (!is_string($encoding_con)) { 43 | printf("FAILURE: no string returned, [%d] %s\n", mysql_errno($con), mysql_error($con)); 44 | } 45 | 46 | mysql_close($con); 47 | ?> 48 | --EXPECT-EXT/MYSQL-OUTPUT-- 49 | SUCCESS: connect 50 | 51 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 52 | --EXPECT-EXT/MYSQLI-OUTPUT-- 53 | SUCCESS: connect 54 | 55 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 56 | --EXPECT-CONVERTER-ERRORS-- 57 | 24, 26, 26, 31, 58 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/FreeResultTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FreeResultTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('free_result001.php'); 29 | 30 | foreach ($files as $k => $file) { 31 | $file = dirname(__FILE__).'/TestCode/'.$file; 32 | $test_spec = $this->parseTestFile($file); 33 | if ($err = $this->validateTestSpec($test_spec)) { 34 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 35 | 36 | return; 37 | } 38 | 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FreeResultTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FreeResultTest::main') { 50 | MySQLConverterTool_FreeResultTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/CreateDBTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_CreateDBTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('create_db001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_CreateDBTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_CreateDBTest::main') { 50 | MySQLConverterTool_CreateDBTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/FieldLenTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FieldLenTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('field_len001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FieldLenTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FieldLenTest::main') { 50 | MySQLConverterTool_FieldLenTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/SelectDBTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_SelectDBTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('select_db001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_SelectDBTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_SelectDBTest::main') { 50 | MySQLConverterTool_SelectDBTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/FieldNameTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FieldNameTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('field_name001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FieldNameTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FieldNameTest::main') { 50 | MySQLConverterTool_FieldNameTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/FieldTypeTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FieldTypeTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('field_type001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FieldTypeTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FieldTypeTest::main') { 50 | MySQLConverterTool_FieldTypeTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/TablenameTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_TablenameTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('tablename001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_TablenameTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_TablenameTest::main') { 50 | MySQLConverterTool_TablenameTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/FetchFieldTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FetchFieldTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('fetch_field001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FetchFieldTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FetchFieldTest::main') { 50 | MySQLConverterTool_FetchFieldTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/FieldFlagsTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FieldFlagsTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('field_flags001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FieldFlagsTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FieldFlagsTest::main') { 50 | MySQLConverterTool_FieldFlagsTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/FieldTableTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_FieldTableTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('field_table001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_FieldTableTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_FieldTableTest::main') { 50 | MySQLConverterTool_FieldTableTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/ListFieldsTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ListFieldsTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('list_fields001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_ListFieldsTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ListFieldsTest::main') { 50 | MySQLConverterTool_ListFieldsTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/ParReversedTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ParReversedTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('par_reversed001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_ParReversedTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ParReversedTest::main') { 50 | MySQLConverterTool_ParReversedTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/EscapeStringTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_EscapeStringTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('escape_string001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_EscapeStringTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_EscapeStringTest::main') { 50 | MySQLConverterTool_EscapeStringTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /GUI/convert_snippet.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Available since Release 1.0 15 | */ 16 | if (isset($_POST['cancel'])) { 17 | // Cancel button 18 | header('Location: index.php'); 19 | exit(0); 20 | } 21 | 22 | require_once 'snippets/MySQLConverterTool_GUI_Snippets.php'; 23 | 24 | $snippet_title = 'MySQL ext/mysql Converter Tool'; 25 | $snippet_greeting = 'Convert a code snippet'; 26 | $snippet_nav_path = array($_SERVER['PHP_SELF'] => 'Convert a code snippet'); 27 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/header.php'); 28 | 29 | if (empty($_POST) || !isset($_POST['start'])) { 30 | // show the form 31 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/form_snippet.php'); 32 | } else { 33 | // process the form 34 | $snippet_errors = array(); 35 | if ('' == trim($_POST['snippet'])) { 36 | $snippet_errors['snippet'] = 'Please provide some code to be converted.'; 37 | } 38 | 39 | if (!empty($snippet_errors)) { 40 | // show the form 41 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/form_snippet.php'); 42 | } else { 43 | // let's try to convert some files... 44 | 45 | require_once '../Converter.php'; 46 | $conv = new MySQLConverterTool_Converter(); 47 | 48 | $snippet_conv = $conv->convertString($_POST['snippet']); 49 | $snippet_show_details = true; 50 | 51 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/show_converted_snippet.php'); 52 | } 53 | } 54 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/footer.php'); 55 | -------------------------------------------------------------------------------- /UnitTests/Converter/ListProcessesTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ListProcessesTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('list_processes001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_ListProcessesTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ListProcessesTest::main') { 50 | MySQLConverterTool_ListProcessesTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/UnbufferedQueryTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_UnbufferedQueryTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('unbuffered_query001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_UnbufferedQueryTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_UnbufferedQueryTest::main') { 50 | MySQLConverterTool_UnbufferedQueryTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/RealEscapeStringTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_RealEscapeStringTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('real_escape_string001.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_RealEscapeStringTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_RealEscapeStringTest::main') { 50 | MySQLConverterTool_RealEscapeStringTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /UnitTests/Converter/GenericBooleanTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_GenericBooleanTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('generic_boolean001.php', 'generic_boolean002.php', 29 | ); 30 | 31 | foreach ($files as $k => $file) { 32 | $file = dirname(__FILE__).'/TestCode/'.$file; 33 | $test_spec = $this->parseTestFile($file); 34 | if ($err = $this->validateTestSpec($test_spec)) { 35 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 36 | 37 | return; 38 | } 39 | if ($err = $this->runTestSpec($test_spec)) { 40 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 41 | 42 | return; 43 | }; 44 | } 45 | } 46 | } 47 | 48 | // Call MySQLConverterTool_GenericBooleanTest::main() if this source file is executed directly. 49 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_GenericBooleanTest::main') { 50 | MySQLConverterTool_GenericBooleanTest::main(); 51 | } 52 | -------------------------------------------------------------------------------- /Function/EscapeString.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_EscapeString extends MySQLConverterTool_Function_Generic 20 | { 21 | public function handle(array $params = array()) 22 | { 23 | 24 | // mysql_escape_string ( string unescaped_string ) 25 | 26 | if (count($params) != 1) { 27 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 28 | } 29 | 30 | list($par1) = $this->extractParamValues($params); 31 | $conn = $this->ston_name; 32 | 33 | $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!'; 34 | $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)) ? "" : ""))', 35 | $conn, 36 | $conn, 37 | $this->new_name, 38 | $conn, 39 | $par1 40 | ); 41 | 42 | return array($warning, $ret); 43 | } 44 | 45 | public function getConversionHint() 46 | { 47 | return 'Emulated using mysqli_real_escape_string and the default connection. If not default connection exists an E_USER_ERROR gets thrown.'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Function/ListTables.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ListTables extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_list_tables ( string database [, resource link_identifier] ) 31 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 32 | 33 | if (count($params) < 1 || count($params) > 2) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | @list($db, $conn) = $this->extractParamValues($params); 38 | if (is_null($conn)) { 39 | $conn = $this->ston_name; 40 | } 41 | 42 | list($db, $db_type) = $this->extractValueAndType(trim($db)); 43 | if ('const' == $db_type) { 44 | $ret = sprintf('mysqli_query(%s, "SHOW TABLES FROM " . constant(\'%s\'))', $conn, $db); 45 | } else { 46 | $ret = sprintf('mysqli_query(%s, "SHOW TABLES FROM `%s`")', $conn, $db); 47 | } 48 | 49 | return array('mysql_list_tables(string database_name [...]) is emulated using mysqli_query() and SHOW TABLES FROM `database_name`. This is a possible SQL injection security bug as no tests are performed what value database_name has. Check your script!', $ret); 50 | } 51 | 52 | public function getConversionHint() 53 | { 54 | return 'Emulated using mysqli_query() and SHOW TABLES FROM.'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /UnitTests/Converter/ConnectTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ConnectTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('connect001.php', 'connect002.php', 'connect003.php', 29 | 'connect004.php', 'connect005.php', 'connect006.php', 30 | 'connect007.php', 31 | ); 32 | 33 | foreach ($files as $k => $file) { 34 | $file = dirname(__FILE__).'/TestCode/'.$file; 35 | $test_spec = $this->parseTestFile($file); 36 | if ($err = $this->validateTestSpec($test_spec)) { 37 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 38 | 39 | return; 40 | } 41 | if ($err = $this->runTestSpec($test_spec)) { 42 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 43 | 44 | return; 45 | }; 46 | } 47 | } 48 | } 49 | 50 | // Call MySQLConverterTool_ConnectTest::main() if this source file is executed directly. 51 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ConnectTest::main') { 52 | MySQLConverterTool_ConnectTest::main(); 53 | } 54 | -------------------------------------------------------------------------------- /UnitTests/Converter/GenericTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_GenericTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('generic001.php', 'generic002.php', 'generic003.php', 29 | 'generic004.php', 'generic005.php', 'generic006.php', 30 | 'generic007.php', 'generic008.php', 31 | ); 32 | 33 | foreach ($files as $k => $file) { 34 | $file = dirname(__FILE__).'/TestCode/'.$file; 35 | $test_spec = $this->parseTestFile($file); 36 | if ($err = $this->validateTestSpec($test_spec)) { 37 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 38 | 39 | return; 40 | } 41 | if ($err = $this->runTestSpec($test_spec)) { 42 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 43 | 44 | return; 45 | }; 46 | } 47 | } 48 | } 49 | 50 | // Call MySQLConverterTool_GenericTest::main() if this source file is executed directly. 51 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_GenericTest::main') { 52 | MySQLConverterTool_GenericTest::main(); 53 | } 54 | -------------------------------------------------------------------------------- /UnitTests/Converter/ConnParamBoolTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ConnParamBoolTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('conn_param_bool001.php', 'conn_param_bool002.php', 'conn_param_bool003.php', 29 | 'conn_param_bool004.php', 'conn_param_bool005.php', 30 | ); 31 | 32 | foreach ($files as $k => $file) { 33 | $file = dirname(__FILE__).'/TestCode/'.$file; 34 | $test_spec = $this->parseTestFile($file); 35 | if ($err = $this->validateTestSpec($test_spec)) { 36 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 37 | 38 | return; 39 | } 40 | if ($err = $this->runTestSpec($test_spec)) { 41 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 42 | 43 | return; 44 | }; 45 | } 46 | } 47 | } 48 | 49 | // Call MySQLConverterTool_ConnParamBoolTest::main() if this source file is executed directly. 50 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ConnParamBoolTest::main') { 51 | MySQLConverterTool_ConnParamBoolTest::main(); 52 | } 53 | -------------------------------------------------------------------------------- /UnitTests/Converter/ConnParamTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Converter_ConnParamTest extends MySQLConverterTool_UnitTests_Converter_ConverterTest 25 | { 26 | public function testConvertFile() 27 | { 28 | $files = array('conn_param001.php', 'conn_param002.php', 'conn_param003.php', 29 | 'conn_param004.php', 'conn_param005.php', 'conn_param006.php', 30 | 'conn_param007.php', 'conn_param008.php', 31 | ); 32 | 33 | foreach ($files as $k => $file) { 34 | $file = dirname(__FILE__).'/TestCode/'.$file; 35 | $test_spec = $this->parseTestFile($file); 36 | if ($err = $this->validateTestSpec($test_spec)) { 37 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 38 | 39 | return; 40 | } 41 | if ($err = $this->runTestSpec($test_spec)) { 42 | $this->fail(sprintf("[%s]\n%s\n", $file, $err)); 43 | 44 | return; 45 | }; 46 | } 47 | } 48 | } 49 | 50 | // Call MySQLConverterTool_ConnParamTest::main() if this source file is executed directly. 51 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_ConnParamTest::main') { 52 | MySQLConverterTool_ConnParamTest::main(); 53 | } 54 | -------------------------------------------------------------------------------- /Function/DBQuery.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_DBQuery extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_db_query ( string database, string query [, resource link_identifier] ) 31 | if (count($params) < 2 || count($params) > 3) { 32 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 33 | } 34 | 35 | @list($new_db, $query, $conn) = $this->extractParamValues($params); 36 | if (is_null($conn)) { 37 | $conn = $this->ston_name; 38 | } 39 | 40 | list($new_db, $new_db_type) = $this->extractValueAndType(trim($new_db)); 41 | if ('const' == $new_db_type) { 42 | $ret = sprintf('((mysqli_query(%s, "USE " . constant(\'%s\'))) ? mysqli_query(%s, %s) : false)', 43 | $conn, 44 | $new_db, 45 | $conn, 46 | $query); 47 | } else { 48 | $ret = sprintf('((mysqli_query(%s, "USE %s")) ? mysqli_query(%s, %s) : false)', 49 | $conn, 50 | $new_db, 51 | $conn, 52 | $query); 53 | } 54 | 55 | 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); 56 | } 57 | 58 | public function getConversionHint() 59 | { 60 | return 'Emulated using mysqli_query and USE.'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param_bool003.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_get_proto_info() 3 | --FILE-- 4 | = 4.0.5, PHP 5) 9 | mysql_get_proto_info -- Get MySQL protocol info 10 | Description 11 | int mysql_get_proto_info ( [resource link_identifier] ) 12 | 13 | Retrieves the MySQL protocol. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns the MySQL protocol on success, or FALSE on failure. 23 | */ 24 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 25 | 26 | $con = mysql_connect($host, $user, $pass); 27 | if (!$con) { 28 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 29 | } else { 30 | echo "SUCCESS: connect\n"; 31 | } 32 | 33 | $proto_info_default = mysql_get_proto_info(); 34 | $proto_info_con = mysql_get_proto_info($con); 35 | if ($proto_info_con != $proto_info_default) { 36 | printf("FAILURE: proto info of default connection and specified connection differ\n"); 37 | } 38 | 39 | if (!is_int($proto_info_con)) { 40 | printf("FAILURE: function should have returned an integer\n"); 41 | } 42 | 43 | $proto_info_con = mysql_get_proto_info($illegal_link_identifier); 44 | if (!is_bool($proto_info_con)) { 45 | printf("FAILURE: function should have returned a boolean value, got %s value\n", gettype($proto_info_con)); 46 | } 47 | 48 | if ($proto_info_con) { 49 | printf("FAILURE: function should have failed with illegal link identifier\n"); 50 | } 51 | 52 | mysql_close($con); 53 | ?> 54 | --EXPECT-EXT/MYSQL-OUTPUT-- 55 | SUCCESS: connect 56 | 57 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 58 | --EXPECT-EXT/MYSQLI-OUTPUT-- 59 | SUCCESS: connect 60 | 61 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 62 | 40, E_NOTICE, Undefined variable: illegal_link_identifier 63 | 40, E_WARNING, mysqli_get_proto_info() expects parameter 1 to be mysqli, null given 64 | --EXPECT-CONVERTER-ERRORS-- 65 | 24, 26, 26, 66 | --ENDOFTEST-- -------------------------------------------------------------------------------- /Function/DropDB.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_DropDB extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_drop_db ( string database_name [, resource link_identifier] ) 31 | if (count($params) < 1 || count($params) > 2) { 32 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 33 | } 34 | 35 | @list($db, $conn) = $this->extractParamValues($params); 36 | if (is_null($conn)) { 37 | $conn = $this->ston_name; 38 | } 39 | 40 | list($db, $db_type) = $this->extractValueAndType(trim($db)); 41 | 42 | if ('const' == $db_type) { 43 | $ret = sprintf('((is_null($___mysqli_res = %s(%s, "DROP DATABASE " . constant(\'%s\')))) ? false : $___mysqli_res)', 44 | $this->new_name, 45 | $conn, 46 | $db 47 | ); 48 | } else { 49 | $ret = sprintf('((is_null($___mysqli_res = %s(%s, "DROP DATABASE %s"))) ? false : $___mysqli_res)', 50 | $this->new_name, 51 | $conn, 52 | $db 53 | ); 54 | } 55 | 56 | 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); 57 | } 58 | 59 | public function getConversionHint() 60 | { 61 | return 'Emulated using mysqli_query and DROP DATABASE.'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param_bool004.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_get_server_info() 3 | --FILE-- 4 | = 4.0.5, PHP 5) 9 | mysql_get_server_info -- Get MySQL server info 10 | Description 11 | string mysql_get_server_info ( [resource link_identifier] ) 12 | 13 | Retrieves the MySQL server version. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns the MySQL server version on success, or FALSE on failure. 23 | */ 24 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 25 | 26 | $con = mysql_connect($host, $user, $pass); 27 | if (!$con) { 28 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 29 | } else { 30 | echo "SUCCESS: connect\n"; 31 | } 32 | 33 | $server_info_default = mysql_get_server_info(); 34 | $server_info_con = mysql_get_server_info($con); 35 | if ($server_info_con != $server_info_default) { 36 | printf("FAILURE: proto info of default connection and specified connection differ\n"); 37 | } 38 | 39 | if (!is_string($server_info_con)) { 40 | printf("FAILURE: function should have returned a string\n"); 41 | } 42 | 43 | $server_info_con = mysql_get_server_info($illegal_link_identifier); 44 | if (!is_bool($server_info_con)) { 45 | printf("FAILURE: function should have returned a boolean value, got %s value\n", gettype($server_info_con)); 46 | } 47 | 48 | if ($server_info_con) { 49 | printf("FAILURE: function should have failed with illegal link identifier\n"); 50 | } 51 | 52 | mysql_close($con); 53 | ?> 54 | --EXPECT-EXT/MYSQL-OUTPUT-- 55 | SUCCESS: connect 56 | 57 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 58 | --EXPECT-EXT/MYSQLI-OUTPUT-- 59 | SUCCESS: connect 60 | 61 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 62 | 40, E_NOTICE, Undefined variable: illegal_link_identifier 63 | 40, E_WARNING, mysqli_get_server_info() expects parameter 1 to be mysqli, null given 64 | --EXPECT-CONVERTER-ERRORS-- 65 | 24, 26, 26, 66 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/escape_string001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_escape_string() 3 | --FILE-- 4 | = 4.0.3, PHP 5) 9 | mysql_escape_string -- Escapes a string for use in a mysql_query 10 | Description 11 | string mysql_escape_string ( string unescaped_string ) 12 | 13 | This function will escape the unescaped_string, so that it is safe to place it in a mysql_query(). This function is deprecated. 14 | 15 | This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting. 16 | Parameters 17 | 18 | unescaped_string 19 | 20 | The string that is to be escaped. 21 | 22 | Return Values 23 | 24 | Returns the escaped string. 25 | */ 26 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 27 | 28 | // I hate ext/mysql - this one does not fail! 29 | $escaped = mysql_escape_string("ext/mysql doesn't fail..."); 30 | if (!is_string($escaped)) { 31 | printf("FAILURE: 1 did not return string value but %s value\n", gettype($escaped)); 32 | } 33 | 34 | var_dump($escaped); 35 | 36 | $con = mysql_connect($host, $user, $pass); 37 | if (!$con) { 38 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 39 | } else { 40 | echo "SUCCESS: connect\n"; 41 | } 42 | 43 | $escaped = mysql_escape_string("ext/mysql and ext/mysqli won't fail..."); 44 | if (!is_string($escaped)) { 45 | printf("FAILURE: 2 did not return string value but %s value\n", gettype($escaped)); 46 | } 47 | 48 | var_dump($escaped); 49 | 50 | mysql_close($con); 51 | ?> 52 | --EXPECT-EXT/MYSQL-OUTPUT-- 53 | string(26) "ext/mysql doesn\'t fail..." 54 | SUCCESS: connect 55 | string(39) "ext/mysql and ext/mysqli won\'t fail..." 56 | 57 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 58 | --EXPECT-EXT/MYSQLI-OUTPUT-- 59 | string(0) "" 60 | SUCCESS: connect 61 | string(39) "ext/mysql and ext/mysqli won\'t fail..." 62 | 63 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 64 | 27, E_USER_ERROR, [MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work. 65 | --EXPECT-CONVERTER-ERRORS-- 66 | 27, 33, 35, 35, 40, 67 | --ENDOFTEST-- -------------------------------------------------------------------------------- /Function/CreateDB.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_CreateDB extends MySQLConverterTool_Function_Generic 20 | { 21 | // not used, but anyway 22 | public $new_name = 'mysqli_query'; 23 | 24 | public function __construct() 25 | { 26 | } 27 | 28 | public function handle(array $params = array()) 29 | { 30 | 31 | // mysql_create_db ( string database_name [, resource link_identifier] ) 32 | 33 | if (count($params) < 1 || count($params) > 2) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | @list($db, $conn) = $this->extractParamValues($params); 38 | if (is_null($conn)) { 39 | $conn = $this->ston_name; 40 | } 41 | 42 | list($db, $db_type) = $this->extractValueAndType(trim($db)); 43 | 44 | if ('const' == $db_type) { 45 | $ret = sprintf('((is_null($___mysqli_res = %s(%s, "CREATE DATABASE " . constant(\'%s\')))) ? false : $___mysqli_res)', 46 | $this->new_name, 47 | $conn, 48 | $db 49 | ); 50 | } else { 51 | $ret = sprintf('((is_null($___mysqli_res = %s(%s, "CREATE DATABASE %s"))) ? false : $___mysqli_res)', 52 | $this->new_name, 53 | $conn, 54 | $db 55 | ); 56 | } 57 | 58 | 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); 59 | } 60 | 61 | public function getConversionHint() 62 | { 63 | return 'Emulated using mysqli_query and CREATE DATABASE.'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param004.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_client_encoding() 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_client_encoding -- Returns the name of the character set 10 | Description 11 | string mysql_client_encoding ( [resource link_identifier] ) 12 | 13 | Retrieves the character_set variable from MySQL. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns the default character set name for the current connection. 23 | */ 24 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 25 | 26 | $con = mysql_connect($host, $user, $pass); 27 | if (!$con) { 28 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 29 | } else { 30 | echo "SUCCESS: connect\n"; 31 | } 32 | 33 | if (!mysql_select_db($db, $con)) { 34 | printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con)); 35 | } 36 | 37 | $encoding_default = mysql_client_encoding(); 38 | $encoding_con = mysql_client_encoding($con); 39 | 40 | if ($encoding_con != $encoding_default) { 41 | printf("FAILURE: different client encodings reported, [%d] %s\n", mysql_errno($con), mysql_error($con)); 42 | } elseif (!is_string($encoding_con)) { 43 | printf("FAILURE: no string returned, [%d] %s\n", mysql_errno($con), mysql_error($con)); 44 | } 45 | 46 | $encoding_con = mysql_client_encoding($illegal_link_identifier); 47 | if (!is_null($encoding_con)) { 48 | printf("FAILURE: NULL value expected, got %s value\n", gettype($encoding_con)); 49 | } 50 | 51 | mysql_close($con); 52 | ?> 53 | --EXPECT-EXT/MYSQL-OUTPUT-- 54 | SUCCESS: connect 55 | 56 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 57 | --EXPECT-EXT/MYSQLI-OUTPUT-- 58 | SUCCESS: connect 59 | 60 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 61 | 43, E_NOTICE, Undefined variable: illegal_link_identifier 62 | 43, E_WARNING, mysqli_character_set_name() expects parameter 1 to be mysqli, null given 63 | --EXPECT-CONVERTER-ERRORS-- 64 | 24, 26, 26, 31, 65 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/FetchFieldTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_FetchFieldTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_FetchFieldTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_FetchField(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // mysql_fetch_field ( resource result, int field_offset ) 42 | // object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr ) 43 | 44 | // too few parameters: parse error 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNotNull($warning); 47 | $this->assertNull($code); 48 | 49 | // we don't test the code that gets returned... that would be, well, check it out... 50 | 51 | // too many parameters: parse error 52 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 53 | $this->assertNotNull($warning); 54 | $this->assertNull($code); 55 | } 56 | } 57 | 58 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_FetchFieldTest::main') { 59 | MySQLConverterTool_Function_FetchFieldTest::main(); 60 | } 61 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param_bool002.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_get_host_info() 3 | --FILE-- 4 | = 4.0.5, PHP 5) 9 | mysql_get_host_info -- Get MySQL host info 10 | Description 11 | string mysql_get_host_info ( [resource link_identifier] ) 12 | 13 | Describes the type of connection in use for the connection, including the server host name. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns a string describing the type of MySQL connection in use for the connection or FALSE on failure. 23 | */ 24 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 25 | 26 | $con = mysql_connect($host, $user, $pass); 27 | if (!$con) { 28 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 29 | } else { 30 | echo "SUCCESS: connect\n"; 31 | } 32 | 33 | $host_info_default = mysql_get_host_info(); 34 | $host_info_con = mysql_get_host_info($con); 35 | if ($host_info_con != $host_info_default) { 36 | printf("FAILURE: host info of default connection and specified connection differ\n"); 37 | } 38 | 39 | if (!is_string($host_info_con)) { 40 | printf("FAILURE: function should have returned a string\n"); 41 | } 42 | 43 | $host_info_con = mysql_get_host_info($illegal_link_identifier); 44 | if (!is_bool($host_info_con)) { 45 | printf("FAILURE: function should have returned a boolean value, got %s value\n", gettype($host_info_con)); 46 | } 47 | 48 | if ($host_info_con) { 49 | printf("FAILURE: function should have failed with illegal link identifier\n"); 50 | } 51 | 52 | mysql_close($con); 53 | ?> 54 | --EXPECT-EXT/MYSQL-OUTPUT-- 55 | SUCCESS: connect 56 | 57 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 58 | --EXPECT-EXT/MYSQLI-OUTPUT-- 59 | SUCCESS: connect 60 | 61 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 62 | 40, E_NOTICE, Undefined variable: illegal_link_identifier 63 | 40, E_WARNING, mysqli_get_host_info() expects parameter 1 to be mysqli, null given 64 | --EXPECT-CONVERTER-ERRORS-- 65 | 24, 26, 26, 66 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/EscapeStringTest.php: -------------------------------------------------------------------------------- 1 | gen = new MySQLConverterTool_Function_EscapeString('mysqli_real_escape_string'); 21 | $this->default_conn = $this->gen->ston_name; 22 | } 23 | 24 | public function testHandle() 25 | { 26 | 27 | // mysql_escape_string ( string unescaped_string ) 28 | // return "$this->new_name($conn, $par1)"; 29 | 30 | // too few parameters: parse error 31 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 32 | $this->assertNotNull($warning); 33 | $this->assertNull($code); 34 | 35 | // mysql_escape_string() 36 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 37 | $this->assertNotNull($warning); 38 | $this->assertEquals( 39 | 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)) ? "" : ""))', 40 | $this->default_conn, 41 | $this->default_conn, 42 | $this->gen->new_name, 43 | $this->default_conn, 44 | '' 45 | ), 46 | $code 47 | ); 48 | 49 | // too many parameters: parse error 50 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 51 | $this->assertNotNull($warning); 52 | $this->assertNull($code); 53 | } 54 | } 55 | 56 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_EscapeStringTest::main') { 57 | MySQLConverterTool_Function_EscapeStringTest::main(); 58 | } 59 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param007.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_stat() 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_stat -- Get current system status 10 | Description 11 | string mysql_stat ( [resource link_identifier] ) 12 | 13 | mysql_stat() returns the current server status. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns a string with the status for uptime, threads, queries, open tables, flush tables and queries per second. For a complete list of other status variables, you have to use the SHOW STATUS SQL command. If link_identifier is invalid, NULL is returned. 23 | 24 | NOTE: DOCUMENTATION IS WRONG - returns NULL instead of FALSE 25 | */ 26 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 27 | 28 | $con = mysql_connect($host, $user, $pass); 29 | if (!$con) { 30 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 31 | } else { 32 | echo "SUCCESS: connect\n"; 33 | } 34 | 35 | if (!mysql_select_db($db, $con)) { 36 | printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con)); 37 | } 38 | 39 | $stat_default = mysql_stat(); 40 | $stat_con = mysql_stat($con); 41 | if ('' == $stat_default || '' == $stat_con) { 42 | printf("FAILURE: got empty strings for mysql_stat()\n"); 43 | } 44 | 45 | if (!is_string($stat_con)) { 46 | printf("FAILURE: string value expected, got %s value\n", gettype($stat_con)); 47 | } 48 | 49 | $stat_con = mysql_stat($illegal_link_identifier); 50 | if (!is_null($stat_con)) { 51 | printf("FAILURE: NULL value expected because of illegal identifier, got %s value\n", gettype($stat_con)); 52 | } 53 | 54 | if ($stat_con) { 55 | printf("FAILURE: false expected\n"); 56 | } 57 | 58 | mysql_close($con); 59 | ?> 60 | --EXPECT-EXT/MYSQL-OUTPUT-- 61 | SUCCESS: connect 62 | 63 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 64 | --EXPECT-EXT/MYSQLI-OUTPUT-- 65 | SUCCESS: connect 66 | 67 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 68 | 45, E_NOTICE, Undefined variable: illegal_link_identifier 69 | 45, E_WARNING, mysqli_stat() expects parameter 1 to be mysqli, null given 70 | --EXPECT-CONVERTER-ERRORS-- 71 | 26, 28, 28, 33, 72 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param005.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_thread_id() 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_thread_id -- Return the current thread ID 10 | Description 11 | int mysql_thread_id ( [resource link_identifier] ) 12 | 13 | Retrieves the current thread ID. If the connection is lost, and a reconnect with mysql_ping() is executed, the thread ID will change. This means only retrieve the thread ID when needed. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | The thread ID on success, or FALSE on failure. 23 | 24 | 25 | NOTE: DOCUMENTATION IS WRONG - NULL on failure! 26 | */ 27 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 28 | 29 | $con = mysql_connect($host, $user, $pass); 30 | if (!$con) { 31 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 32 | } else { 33 | echo "SUCCESS: connect\n"; 34 | } 35 | 36 | if (!mysql_select_db($db, $con)) { 37 | printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con)); 38 | } 39 | 40 | $id_default = mysql_thread_id(); 41 | $id_con = mysql_thread_id($con); 42 | 43 | if ($id_default != $id_con) { 44 | printf("FAILURE: Different values for default and specified connection\n"); 45 | } 46 | 47 | if (!is_int($id_con)) { 48 | printf("FAILURE: Function should have returned an integer value, got %s value\n", gettype($id_con)); 49 | } 50 | 51 | $id_con = mysql_thread_id($illegal_link_identifier); 52 | if (!is_null($id_con)) { 53 | printf("FAILURE: Function should have returned a NULL value, got %s value\n", gettype($id_con)); 54 | } 55 | 56 | if ($id_con !== null) { 57 | printf("FAILURE: Should return NULL because of illegal link identifier\n"); 58 | } 59 | 60 | mysql_close($con); 61 | ?> 62 | --EXPECT-EXT/MYSQL-OUTPUT-- 63 | SUCCESS: connect 64 | 65 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 66 | --EXPECT-EXT/MYSQLI-OUTPUT-- 67 | SUCCESS: connect 68 | 69 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 70 | 47, E_NOTICE, Undefined variable: illegal_link_identifier 71 | 47, E_WARNING, mysqli_thread_id() expects parameter 1 to be mysqli, null given 72 | --EXPECT-CONVERTER-ERRORS-- 73 | 27, 29, 29, 34, 74 | --ENDOFTEST-- -------------------------------------------------------------------------------- /GUI/snippets/header.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Available since Release 1.0 15 | */ 16 | ?> 17 | 18 | 19 | 20 | <?php echo (isset($snippet_title)) ? $snippet_title : 'MySQL ext/mysql Converter Tool'; ?> 21 | 22 | 47 | 48 | 49 |
50 | 51 | 52 | 62 | 63 | 64 |
53 | Home 54 | $label) { 57 | printf(' --> %s', $link, $label); 58 | } 59 | } 60 | ?> 61 | Help
65 |
66 |
67 |

68 |
69 |
70 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/field_len001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_field_len() 3 | --FILE-- 4 | 74 | --EXPECT-EXT/MYSQL-OUTPUT-- 75 | SUCCESS: connect 76 | 77 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 78 | --EXPECT-EXT/MYSQLI-OUTPUT-- 79 | SUCCESS: connect 80 | 81 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 82 | --EXPECT-CONVERTER-ERRORS-- 83 | 27, 29, 29, 34, 84 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/FreeResultTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_FreeResultTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_FreeResultTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_FreeResult(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // bool mysql_free_result ( resource result ) 42 | // void mysqli_free_result ( mysqli_result result ) 43 | 44 | // too few parameters: parse error 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNotNull($warning); 47 | $this->assertNull($code); 48 | 49 | // bool mysql_free_result ( resource result ) 50 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 51 | $this->assertNull($warning); 52 | $this->assertEquals( 53 | '((mysqli_free_result() || (is_object() && (get_class() == "mysqli_result"))) ? true : false)', 54 | $code 55 | ); 56 | 57 | // too many parameters: parse error 58 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 59 | $this->assertNotNull($warning); 60 | $this->assertNull($code); 61 | } 62 | } 63 | 64 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_FreeResultTest::main') { 65 | MySQLConverterTool_Function_FreeResultTest::main(); 66 | } 67 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/error002.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_error() 3 | --FILE-- 4 | 55 | --EXPECT-EXT/MYSQL-OUTPUT-- 56 | SUCCESS: connect 57 | 58 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 59 | --EXPECT-EXT/MYSQLI-OUTPUT-- 60 | SUCCESS: connect 61 | 62 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 63 | 40, E_NOTICE, Undefined variable: illegal_link_identifier 64 | --EXPECT-CONVERTER-ERRORS-- 65 | 24, 26, 26, 36, 66 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/error001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_errno() 3 | --FILE-- 4 | 57 | --EXPECT-EXT/MYSQL-OUTPUT-- 58 | SUCCESS: connect 59 | 60 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 61 | --EXPECT-EXT/MYSQLI-OUTPUT-- 62 | SUCCESS: connect 63 | 64 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 65 | 42, E_NOTICE, Undefined variable: illegal_link_identifier 66 | --EXPECT-CONVERTER-ERRORS-- 67 | 26, 28, 28, 38, 68 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param006.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_ping() 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_ping -- Ping a server connection or reconnect if there is no connection 10 | Description 11 | bool mysql_ping ( [resource link_identifier] ) 12 | 13 | Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by scripts that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns TRUE if the connection to the server MySQL server is working, otherwise FALSE. 23 | 24 | NOTE: DOCUMENTATION IS WRONG - returns NULL instead of FALSE 25 | */ 26 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 27 | 28 | $con = mysql_connect($host, $user, $pass); 29 | if (!$con) { 30 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 31 | } else { 32 | echo "SUCCESS: connect\n"; 33 | } 34 | 35 | if (!mysql_select_db($db, $con)) { 36 | printf("FAILURE: [%d] %s\n", mysql_errno($con), mysql_error($con)); 37 | } 38 | 39 | $ping_default = mysql_ping(); 40 | $ping_con = mysql_ping($con); 41 | if ($ping_default != $ping_con) { 42 | printf("FAILURE: different values returned for ping with specified and default connection\n"); 43 | } 44 | 45 | if (!is_bool($ping_con)) { 46 | printf("FAILURE: boolean value expected, got %s value\n", gettype($ping_con)); 47 | } 48 | 49 | $ping_con = mysql_ping($illegal_link_identifier); 50 | if (!is_null($ping_con)) { 51 | printf("FAILURE: NULL value expected because of illegal identifier, got %s value\n", gettype($ping_con)); 52 | } 53 | 54 | if ($ping_con) { 55 | printf("FAILURE: false expected\n"); 56 | } 57 | 58 | mysql_close($con); 59 | ?> 60 | --EXPECT-EXT/MYSQL-OUTPUT-- 61 | SUCCESS: connect 62 | 63 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 64 | --EXPECT-EXT/MYSQLI-OUTPUT-- 65 | SUCCESS: connect 66 | 67 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 68 | 45, E_NOTICE, Undefined variable: illegal_link_identifier 69 | 45, E_WARNING, mysqli_ping() expects parameter 1 to be mysqli, null given 70 | --EXPECT-CONVERTER-ERRORS-- 71 | 26, 28, 28, 33, 72 | --ENDOFTEST-- -------------------------------------------------------------------------------- /Function/ListFields.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 11 | * @copyright 1997-2006 The PHP Group 12 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 13 | * 14 | * @version CVS: $Id:$, Release: @package_version@ 15 | * 16 | * @link http://www.mysql.com 17 | * @since Class available since Release 1.0 18 | */ 19 | class MySQLConverterTool_Function_ListFields extends MySQLConverterTool_Function_Generic 20 | { 21 | public $new_name = 'mysqli_query'; 22 | 23 | public function __construct() 24 | { 25 | } 26 | 27 | public function handle(array $params = array()) 28 | { 29 | 30 | // mysql_list_fields ( string database_name, string table_name [, resource link_identifier] ) 31 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 32 | 33 | if (count($params) < 2 || count($params) > 3) { 34 | return array(self::PARSE_ERROR_WRONG_PARAMS, null); 35 | } 36 | 37 | @list($db, $table, $conn) = $this->extractParamValues($params); 38 | if (is_null($conn)) { 39 | $conn = $this->ston_name; 40 | } 41 | 42 | list($db, $db_type) = $this->extractValueAndType(trim($db)); 43 | list($table, $table_type) = $this->extractValueAndType(trim($table)); 44 | 45 | $sql = '"SHOW COLUMNS FROM '; 46 | if ($db_type == 'const') { 47 | $sql .= '" . constant(\''.$db.'\') . ".'; 48 | } else { 49 | $sql .= $db.'.'; 50 | } 51 | 52 | if ($table_type == 'const') { 53 | $sql .= '" . constant(\''.$table.'\')'; 54 | } else { 55 | $sql .= $table.'"'; 56 | } 57 | 58 | $ret = sprintf('(($___mysqli_tmp = mysqli_query(%s, %s)) ? $___mysqli_tmp : false)', $conn, $sql); 59 | 60 | return array( 61 | 'mysql_list_fields(string database_name, string table_name [...]) is emulated using mysqli_query() and SHOW COLUMNS FROM database_name.table_name . This is a possible SQL injection security bug as no tests are performed what value database_name and/or table_name have. Check your script! Additionally, this is not fully compatible to the original expression, check the mysql_list_fields() documentation on php.net!', $ret, ); 62 | } 63 | 64 | public function getConversionHint() 65 | { 66 | return 'Emulated using mysqli_query() and SHOW COLUMNS FROM table'; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/real_escape_string001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_real_escape_string 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_real_escape_string -- Escapes special characters in a string for use in a SQL statement 10 | Description 11 | string mysql_real_escape_string ( string unescaped_string [, resource link_identifier] ) 12 | 13 | Escapes special characters in the unescaped_string, taking into account the current character set of the connection so that it is safe to place it in a mysql_query(). If binary data is to be inserted, this function must be used. 14 | 15 | mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a. 16 | 17 | This function must always (with few exceptions) be used to make data safe before sending a query to MySQL. 18 | Parameters 19 | 20 | unescaped_string 21 | 22 | The string that is to be escaped. 23 | link_identifier 24 | 25 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 26 | 27 | Return Values 28 | 29 | Returns the escaped string, or FALSE on error. 30 | 31 | */ 32 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 33 | 34 | $con = mysql_connect($host, $user, $pass); 35 | if (!$con) { 36 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 37 | } else { 38 | echo "SUCCESS: connect\n"; 39 | } 40 | 41 | if (!mysql_select_db($db, $con)) { 42 | printf("FAILURE: cannot select db '%s', [%d] %s\n", 43 | $db, mysql_errno($con), mysql_error($con)); 44 | } 45 | 46 | $escaped = mysql_real_escape_string("Let's escape this"); 47 | if ($escaped !== "Let\'s escape this") { 48 | printf("FAILURE: escape with default connection did not work, [%d] %s\n", mysql_errno(), mysql_error()); 49 | } 50 | 51 | $escaped = mysql_real_escape_string("Let's escape this", $con); 52 | if ($escaped !== "Let\'s escape this") { 53 | printf("FAILURE: escape did not work, [%d] %s\n", mysql_errno($con), mysql_error($con)); 54 | } 55 | 56 | mysql_close($con); 57 | ?> 58 | --EXPECT-EXT/MYSQL-OUTPUT-- 59 | SUCCESS: connect 60 | 61 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 62 | --EXPECT-EXT/MYSQLI-OUTPUT-- 63 | SUCCESS: connect 64 | 65 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 66 | --EXPECT-CONVERTER-ERRORS-- 67 | 32, 34, 34, 39, 43, 45, 45, 68 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param_bool001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_close() - behaves differently for illegal link identifier, extra cast 3 | --FILE-- 4 | 62 | --EXPECT-EXT/MYSQL-OUTPUT-- 63 | SUCCESS: connect 64 | SUCCESS: connect 65 | 66 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 67 | --EXPECT-EXT/MYSQLI-OUTPUT-- 68 | SUCCESS: connect 69 | SUCCESS: connect 70 | 71 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 72 | 48, E_NOTICE, Undefined variable: invalid_link_identifier 73 | 48, E_WARNING, mysqli_close() expects parameter 1 to be mysqli, null given 74 | --EXPECT-CONVERTER-ERRORS-- 75 | 26, 28, 28, 37, 39, 39, 76 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/field_table001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_field_table() 3 | --FILE-- 4 | 74 | --EXPECT-EXT/MYSQL-OUTPUT-- 75 | SUCCESS: connect 76 | 77 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 78 | --EXPECT-EXT/MYSQLI-OUTPUT-- 79 | SUCCESS: connect 80 | 81 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 82 | 56, E_WARNING, mysqli_fetch_field_direct(): Field offset is invalid for resultset 83 | 56, E_NOTICE, Trying to get property of non-object 84 | --EXPECT-CONVERTER-ERRORS-- 85 | 27, 29, 29, 34, 86 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/ListDBsTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_ListDBsTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_ListDBsTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_ListDBs(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // mysql_list_dbs ( [resource link_identifier] ) 42 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 43 | 44 | // mysql_list_dbs () 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNull($warning); 47 | $this->assertEquals( 48 | sprintf('(($___mysqli_tmp = mysqli_query(%s, "SHOW DATABASES")) ? $___mysqli_tmp : false)', $this->default_conn), 49 | $code 50 | ); 51 | 52 | // mysql_list_dbs () 53 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 54 | $this->assertNull($warning); 55 | $this->assertEquals( 56 | '(($___mysqli_tmp = mysqli_query(, "SHOW DATABASES")) ? $___mysqli_tmp : false)', 57 | $code 58 | ); 59 | 60 | // too many parameters: parse error 61 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 62 | $this->assertNotNull($warning); 63 | $this->assertNull($code); 64 | } 65 | } 66 | 67 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_ListDBsTest::main') { 68 | MySQLConverterTool_Function_ListDBsTest::main(); 69 | } 70 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/field_name001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_field_name() 3 | --FILE-- 4 | 74 | --EXPECT-EXT/MYSQL-OUTPUT-- 75 | SUCCESS: connect 76 | 77 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 78 | --EXPECT-EXT/MYSQLI-OUTPUT-- 79 | SUCCESS: connect 80 | 81 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 82 | 56, E_WARNING, mysqli_fetch_field_direct(): Field offset is invalid for resultset 83 | 56, E_NOTICE, Trying to get property of non-object 84 | --EXPECT-CONVERTER-ERRORS-- 85 | 27, 29, 29, 34, 86 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/TablenameTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_TablenameTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_TablenameTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_Tablename(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // string mysql_tablename ( resource result, int i ) 42 | 43 | // too few parameters: parse error 44 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 45 | $this->assertNotNull($warning); 46 | $this->assertNull($code); 47 | 48 | // too few parameters: parse error 49 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 50 | $this->assertNotNull($warning); 51 | $this->assertNull($code); 52 | 53 | // mysql_select_db(<$database_name>) 54 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 55 | $this->assertEquals( 56 | '((mysqli_data_seek(, ) && (($___mysqli_tmp = mysqli_fetch_row()) !== NULL)) ? array_shift($___mysqli_tmp) : false)', 57 | $code 58 | ); 59 | 60 | // too many parameters: parse error 61 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 62 | $this->assertNotNull($warning); 63 | $this->assertNull($code); 64 | } 65 | } 66 | 67 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_TablenameTest::main') { 68 | MySQLConverterTool_Function_TablenameTest::main(); 69 | } 70 | -------------------------------------------------------------------------------- /UnitTests/Function/ListProcessesTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_ListProcessesTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_ListProcessesTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_ListProcesses(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // resource mysql_list_processes ( [resource link_identifier] ) 42 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 43 | 44 | // mysql_list_processes() 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNull($warning); 47 | $this->assertEquals( 48 | sprintf('%s(%s, "SHOW PROCESSLIST")', $this->gen->new_name, $this->default_conn), 49 | $code 50 | ); 51 | 52 | // mysql_list_processes() 53 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 54 | $this->assertNull($warning); 55 | $this->assertEquals( 56 | sprintf('%s(, "SHOW PROCESSLIST")', $this->gen->new_name), 57 | $code 58 | ); 59 | 60 | // too many parameters: parse error 61 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 62 | $this->assertNotNull($warning); 63 | $this->assertNull($code); 64 | } 65 | } 66 | 67 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_ListProcessesTest::main') { 68 | MySQLConverterTool_Function_ListProcessesTest::main(); 69 | } 70 | -------------------------------------------------------------------------------- /UnitTests/README: -------------------------------------------------------------------------------- 1 | +++ WARNING +++ 2 | 3 | The PHPUnit version that was used is NOT the PEAR version of PHPUnit 4 | Download PHPUnit 2.3+ from its new home on http://www.phpunit.de! 5 | 6 | +++ Introduction +++ 7 | 8 | The converter tool uses PHPUnit for its tests. Two types of tests are 9 | implemented: 10 | 11 | a) classical unit tests 12 | b) "real-life" examples 13 | 14 | The classical unit tests are contained in the folder UnitTests/Function/. 15 | The tests in that folder mainly check if the mysql_*->mysqli_* transformation 16 | callback function functions behave as expected. E.g. they check if 17 | invalid numbers of parameters are recognized and a warning gets thrown. 18 | The don't really test the scanner/parser not do they check if the code 19 | generated by the converter can be 1) run and 2) behaves in the same 20 | way as the original code. 21 | 22 | This is tested using "real-life" examples contained in the folder 23 | UnitTests/Converter/. Have a look at the files in the folder 24 | UnitTests/Converter/TestCode. The tests look very similar 25 | to the *.phpt files which PHP uses to test extensions. 26 | 27 | PHPUnit acts only as a wrapper to read the files in the folder 28 | UnitTests/Converter/TestCode. E.g. UnitTests/Converter/ConnParamTest.php 29 | does nothing but load and execute (eval) the test files conn_param001.php 30 | to conn_param007.php and groups them together in one PHPUnit test case. 31 | 32 | If you want to add new tests for a certain mysql_* function, check out 33 | which mysql_*->mysqli_ transformation callback function is responsible for 34 | the conversion. There's a list of all function mappings in the file 35 | Converter.php. Once you know which transformation function gets used, 36 | open the corresponding test class in UnitTests/Converter/, e.g. 37 | UnitTests/Converter/DropDBTest for mysql_drop_db. Add a new file to 38 | the list of files in the $files array and implement your new test. 39 | 40 | +++ Running the tests +++ 41 | 42 | The preferred way to run the tests is to call UnitTests/AllTests.php. 43 | It's assumed that you have the phpunit in your PATH. 44 | It's also assumed that you are one level above the installation 45 | directory of the converter tool when you call: 46 | 47 | shell> phpunit MyConverterTool/UnitTests/AllTests.php 48 | 49 | Before you run the "real-life" tests, you must set up a test database and 50 | adapt the configuration file UnitTests/Converter/TestCode/config.php. 51 | The file contains the necessary SQL commands for setting up the database 52 | and the user accounts. Make sure that you remove the test users and 53 | test database from your system after you've run the tests. Default 54 | users and default passwords are not very secure... -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/generic_boolean002.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_num_fields 3 | --FILE-- 4 | 71 | --EXPECT-EXT/MYSQL-OUTPUT-- 72 | SUCCESS: connect 73 | 74 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 75 | --EXPECT-EXT/MYSQLI-OUTPUT-- 76 | SUCCESS: connect 77 | 78 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 79 | 53, E_NOTICE, Undefined variable: illegal_result_identifier 80 | 53, E_WARNING, mysqli_num_fields() expects parameter 1 to be mysqli_result, null given 81 | --EXPECT-CONVERTER-ERRORS-- 82 | 24, 26, 26, 31, 83 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/FieldTableTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_FieldTableTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_FieldTableTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_FieldTable(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // string mysql_field_table ( resource result, int field_offset ) 42 | // object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr ) 43 | 44 | // too few parameters: parse error 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNotNull($warning); 47 | $this->assertNull($code); 48 | 49 | // too few parameters: parse error 50 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 51 | $this->assertNotNull($warning); 52 | $this->assertNull($code); 53 | 54 | // string mysql_field_table ( , ) 55 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 56 | $this->assertNull($warning); 57 | $this->assertEquals( 58 | '(mysqli_fetch_field_direct(, )->table)', 59 | $code 60 | ); 61 | 62 | // too many parameters: parse error 63 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 64 | $this->assertNotNull($warning); 65 | $this->assertNull($code); 66 | } 67 | } 68 | 69 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_FieldTableTest::main') { 70 | MySQLConverterTool_Function_FieldTableTest::main(); 71 | } 72 | -------------------------------------------------------------------------------- /UnitTests/Function/FieldLenTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_FieldLenTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_FieldLenTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_FieldLen(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // mysql_field_len ( resource result, int field_offset ) 42 | // object mysqli_fetch_field_direct ( mysqli_result result, int fieldnr ) 43 | 44 | // too few parameters: parse error 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNotNull($warning); 47 | $this->assertNull($code); 48 | 49 | // too few parameters: parse error 50 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 51 | $this->assertNotNull($warning); 52 | $this->assertNull($code); 53 | 54 | // mysql_field_flags(, 55 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '1'))); 56 | $this->assertNull($warning); 57 | $this->assertEquals( 58 | '((($___mysqli_tmp = mysqli_fetch_fields()) && (isset($___mysqli_tmp[1]))) ? $___mysqli_tmp[1]->length : false)', 59 | $code 60 | ); 61 | 62 | // too many parameters: parse error 63 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 64 | $this->assertNotNull($warning); 65 | $this->assertNull($code); 66 | } 67 | } 68 | 69 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_FieldLenTest::main') { 70 | MySQLConverterTool_Function_FieldLenTest::main(); 71 | } 72 | -------------------------------------------------------------------------------- /UnitTests/Function/FieldNameTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_FieldNameTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_FieldNameTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_FieldName(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // string mysql_field_name ( resource result, int field_offset ) 42 | // mysqli_fetch_field_direct ( mysqli_result result, int fieldnr ) 43 | 44 | // too few parameters: parse error 45 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 46 | $this->assertNotNull($warning); 47 | $this->assertNull($code); 48 | 49 | // too few parameters: parse error 50 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 51 | $this->assertNotNull($warning); 52 | $this->assertNull($code); 53 | 54 | // string mysql_field_name ( , ) 55 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '1'))); 56 | $this->assertNull($warning); 57 | $this->assertEquals( 58 | '((($___mysqli_tmp = mysqli_fetch_field_direct(, 1)->name) && (!is_null($___mysqli_tmp))) ? $___mysqli_tmp : false)', 59 | $code 60 | ); 61 | 62 | // too many parameters: parse error 63 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 64 | $this->assertNotNull($warning); 65 | $this->assertNull($code); 66 | } 67 | } 68 | 69 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_FieldNameTest::main') { 70 | MySQLConverterTool_Function_FieldNameTest::main(); 71 | } 72 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysqli_affected_rows() 3 | --FILE-- 4 | 0) { 49 | printf("FAILURE: one row should have been affected, %d reported\n", $affected); 50 | } elseif ($affected == -1) { 51 | printf("FAILURE: command failed, -1 returned\n"); 52 | } 53 | 54 | mysql_close($con); 55 | ?> 56 | --EXPECT-EXT/MYSQL-OUTPUT-- 57 | SUCCESS: connect 58 | SUCCESS: one row affected 59 | 60 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 61 | --EXPECT-EXT/MYSQLI-OUTPUT-- 62 | SUCCESS: connect 63 | SUCCESS: one row affected 64 | 65 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 66 | --EXPECT-CONVERTER-ERRORS-- 67 | 28, 30, 30, 35, 68 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/UnbufferedQueryTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_UnbufferedQueryTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_UnbufferedQueryTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_UnbufferedQuery(); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // mysql_unbuffered_query ( string query [, resource link_identifier] ) 42 | 43 | // too few parameters: parse error 44 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 45 | $this->assertNotNull($warning); 46 | $this->assertNull($code); 47 | 48 | // mysql_unbuffered_query() 49 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 50 | $this->assertEquals( 51 | sprintf('%s(%s, , MYSQLI_USE_RESULT)', $this->gen->new_name, $this->default_conn), 52 | $code 53 | ); 54 | 55 | // mysql_unbuffered_query(, ) 56 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 57 | $this->assertEquals( 58 | sprintf('%s(, , MYSQLI_USE_RESULT)', $this->gen->new_name), 59 | $code 60 | ); 61 | 62 | // too many parameters: parse error 63 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 64 | $this->assertNotNull($warning); 65 | $this->assertNull($code); 66 | } 67 | } 68 | 69 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_UnbufferedQueryTest::main') { 70 | MySQLConverterTool_Function_UnbufferedQueryTest::main(); 71 | } 72 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param002.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysqli_affected_rows(), default connection 3 | --FILE-- 4 | 0) { 49 | printf("FAILURE: one row should have been affected, %d reported\n", $affected); 50 | } elseif ($affected == -1) { 51 | printf("FAILURE: command failed, -1 returned\n"); 52 | } 53 | 54 | mysql_close($con); 55 | ?> 56 | --EXPECT-EXT/MYSQL-OUTPUT-- 57 | SUCCESS: connect 58 | SUCCESS: one row affected 59 | 60 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 61 | --EXPECT-EXT/MYSQLI-OUTPUT-- 62 | SUCCESS: connect 63 | SUCCESS: one row affected 64 | 65 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 66 | --EXPECT-CONVERTER-ERRORS-- 67 | 28, 30, 30, 35, 39, 39, 68 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/tablename001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_tablename 3 | --FILE-- 4 | 85 | --EXPECT-EXT/MYSQL-OUTPUT-- 86 | SUCCESS: connect 87 | 88 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 89 | --EXPECT-EXT/MYSQLI-OUTPUT-- 90 | SUCCESS: connect 91 | 92 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 93 | 66, E_NOTICE, Undefined variable: illegal_result_identifier 94 | 66, E_WARNING, mysqli_data_seek() expects parameter 1 to be mysqli_result, null given 95 | --EXPECT-CONVERTER-ERRORS-- 96 | 31, 33, 33, 38, 97 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/list_dbs001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_list_dbs() 3 | --FILE-- 4 | 70 | --EXPECT-EXT/MYSQL-OUTPUT-- 71 | SUCCESS: connect 72 | 73 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 74 | --EXPECT-EXT/MYSQLI-OUTPUT-- 75 | SUCCESS: connect 76 | 77 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 78 | 53, E_NOTICE, Undefined variable: illegal_link_identifier 79 | 53, E_WARNING, mysqli_query() expects parameter 1 to be mysqli, null given 80 | 60, E_WARNING, mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given 81 | --EXPECT-CONVERTER-ERRORS-- 82 | 24, 26, 26, 83 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/RealEscapeStringTest.php: -------------------------------------------------------------------------------- 1 | gen = new MySQLConverterTool_Function_RealEscapeString('mysqli_real_escape_string'); 21 | $this->default_conn = $this->gen->ston_name; 22 | } 23 | 24 | public function testHandle() 25 | { 26 | 27 | // string mysql_real_escape_string ( string unescaped_string [, resource link_identifier] ) 28 | // string mysqli_real_escape_string ( mysqli link, string escapestr ) 29 | 30 | // too few parameters: parse error 31 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 32 | $this->assertNotNull($warning); 33 | $this->assertNull($code); 34 | 35 | // mysql_real_escape_string() 36 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 37 | $this->assertNotNull($warning); 38 | $this->assertEquals( 39 | 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)) ? "" : ""))', 40 | $this->default_conn, 41 | $this->default_conn, 42 | $this->gen->new_name, 43 | $this->default_conn, 44 | '' 45 | ), 46 | $code 47 | ); 48 | 49 | // mysql_real_escape_string() 50 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 51 | $this->assertNull($warning); 52 | $this->assertEquals( 53 | sprintf('%s(%s, %s)', 54 | $this->gen->new_name, 55 | '', 56 | '' 57 | ), 58 | $code 59 | ); 60 | 61 | // too many parameters: parse error 62 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 63 | $this->assertNotNull($warning); 64 | $this->assertNull($code); 65 | } 66 | } 67 | 68 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_RealEscapeStringTest::main') { 69 | MySQLConverterTool_Function_RealEscapeStringTest::main(); 70 | } 71 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/conn_param008.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_info() 3 | --FILE-- 4 | = 4.3.0, PHP 5) 9 | mysql_info -- Get information about the most recent query 10 | Description 11 | string mysql_info ( [resource link_identifier] ) 12 | 13 | Returns detailed information about the last query. 14 | Parameters 15 | 16 | link_identifier 17 | 18 | The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level warning is generated. 19 | 20 | Return Values 21 | 22 | Returns information about the statement on success, or FALSE on failure. See the example below for which statements provide information, and what the returned value may look like. Statements that are not listed will return FALSE. 23 | */ 24 | require 'MySQLConverterTool/UnitTests/Converter/TestCode/config.php'; 25 | 26 | $con = mysql_connect($host, $user, $pass); 27 | if (!$con) { 28 | printf("FAILURE: [%d] %s\n", mysql_errno(), mysql_error()); 29 | } else { 30 | echo "SUCCESS: connect\n"; 31 | } 32 | 33 | if (!mysql_select_db($db, $con)) { 34 | printf("FAILURE: could not select database %s, [%d] %s\n", $db, mysql_errno($con), mysql_error($con)); 35 | } 36 | 37 | if (!mysql_query('DELETE FROM nobody', $con)) { 38 | printf("FAILURE: could not clear table nobody, [%d] %s\n", mysql_errno($con), mysql_error($con)); 39 | } 40 | 41 | $res = mysql_query('INSERT INTO nobody(id, msg) VALUES (1, "mysql_info()"), (2, "mysqli_info()")', $con); 42 | if (!$res) { 43 | printf("FAILURE: insert failed, [%d] %s\n", mysql_errno($con), mysql_error($con)); 44 | } 45 | 46 | $info_default = mysql_info(); 47 | $info_con = mysql_info($con); 48 | if ($info_con != $info_default) { 49 | printf("FAILURE: info of default connection and specified connection differ\n"); 50 | } 51 | 52 | if (!is_string($info_con)) { 53 | printf("FAILURE: function should have returned a string, got %s value\n", gettype($info_con)); 54 | } 55 | 56 | var_dump($info_con); 57 | 58 | $info_con = mysql_info($illegal_link_identifier); 59 | if (!is_null($info_con)) { 60 | printf("FAILURE: function should have returned a NULL value, got %s value\n", gettype($info_con)); 61 | } 62 | 63 | if ($info_con) { 64 | printf("FAILURE: function should have failed with illegal link identifier\n"); 65 | } 66 | 67 | mysql_close($con); 68 | ?> 69 | --EXPECT-EXT/MYSQL-OUTPUT-- 70 | SUCCESS: connect 71 | string(38) "Records: 2 Duplicates: 0 Warnings: 0" 72 | 73 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 74 | --EXPECT-EXT/MYSQLI-OUTPUT-- 75 | SUCCESS: connect 76 | string(38) "Records: 2 Duplicates: 0 Warnings: 0" 77 | 78 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 79 | 52, E_NOTICE, Undefined variable: illegal_link_identifier 80 | 52, E_WARNING, mysqli_info() expects parameter 1 to be mysqli, null given 81 | --EXPECT-CONVERTER-ERRORS-- 82 | 24, 26, 26, 31, 83 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/ParReversedTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 16 | * @copyright 1997-2006 The PHP Group 17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 18 | * 19 | * @version CVS: $Id:$, Release: @package_version@ 20 | * 21 | * @link http://www.mysql.com 22 | * @since Class available since Release 1.0 23 | */ 24 | class MySQLConverterTool_UnitTests_Function_ParReversedTest extends MySQLConverterTool_UnitTests_Function_GenericTest 25 | { 26 | public static function main() 27 | { 28 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_UnitTests_Function_ParReversedTest'); 29 | $result = PHPUnit_TextUI_TestRunner::run($suite); 30 | } 31 | 32 | protected function setUp() 33 | { 34 | $this->gen = new MySQLConverterTool_Function_ParReversed('mysql_query'); 35 | $this->default_conn = $this->gen->ston_name; 36 | } 37 | 38 | public function testHandle() 39 | { 40 | 41 | // mysql_query ( string query [, resource link_identifier] ) 42 | // mixed mysqli_query ( mysqli link, string query [, int resultmode] ) 43 | // string mysql_real_escape_string ( string unescaped_string [, resource link_identifier] ) 44 | // string mysqli_real_escape_string ( mysqli link, string escapestr ) 45 | 46 | // too few parameters: parse error 47 | list($warning, $code) = $this->gen->handle($this->buildParams(array())); 48 | $this->assertNotNull($warning); 49 | $this->assertNull($code); 50 | 51 | // mysql_query() 52 | list($warning, $code) = $this->gen->handle($this->buildParams(array(''))); 53 | $this->assertNull($warning); 54 | $this->assertEquals( 55 | sprintf('%s(%s, )', $this->gen->new_name, $this->default_conn), 56 | $code 57 | ); 58 | 59 | // mysql_query(, ) 60 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', ''))); 61 | $this->assertNull($warning); 62 | $this->assertEquals( 63 | sprintf('%s(, )', $this->gen->new_name), 64 | $code 65 | ); 66 | 67 | // too many parameters: parse error 68 | list($warning, $code) = $this->gen->handle($this->buildParams(array('', '', ''))); 69 | $this->assertNotNull($warning); 70 | $this->assertNull($code); 71 | } 72 | } 73 | 74 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_ParReversedTest::main') { 75 | MySQLConverterTool_Function_ParReversedTest::main(); 76 | } 77 | -------------------------------------------------------------------------------- /GUI/convert_file.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 8 | * @copyright 1997-2006 The PHP Group 9 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 10 | * 11 | * @version CVS: $Id:$, Release: @package_version@ 12 | * 13 | * @link http://www.mysql.com 14 | * @since Available since Release 1.0 15 | */ 16 | 17 | if (isset($_POST['cancel'])) { 18 | // Cancel button 19 | header('Location: index.php'); 20 | exit(0); 21 | } 22 | 23 | require_once 'snippets/MySQLConverterTool_GUI_Snippets.php'; 24 | 25 | $snippet_title = 'MySQL ext/mysql Converter Tool'; 26 | $snippet_greeting = 'Convert a file'; 27 | $snippet_nav_path = array($_SERVER['PHP_SELF'] => 'Convert a file'); 28 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/header.php'); 29 | 30 | if (empty($_POST) || !isset($_POST['start'])) { 31 | // show the form 32 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/form_file.php'); 33 | } else { 34 | // process the form 35 | $snippet_errors = array(); 36 | if ('' == trim($_POST['file'])) { 37 | $snippet_errors['file'] = 'Please specify a file.'; 38 | } 39 | 40 | if (!file_exists($_POST['file']) || !is_file($_POST['file']) || !is_readable($_POST['file'])) { 41 | $snippet_errors['file'] = 'Problems reading the file. Please verify that it exists and can be read.'; 42 | } 43 | 44 | if (!empty($snippet_errors)) { 45 | // show the form 46 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/form_file.php'); 47 | } else { 48 | // let's try to convert some files... 49 | 50 | require_once '../Converter.php'; 51 | $conv = new MySQLConverterTool_Converter(); 52 | 53 | $snippet_file = $_POST['file']; 54 | $snippet_conv = $conv->convertFile($_POST['file']); 55 | 56 | if (isset($_POST['update']) && $_POST['update'] == 'yes') { 57 | if (isset($_POST['backup']) && $_POST['backup'] == 'on') { 58 | if (file_exists($snippet_file.'.org')) { 59 | unlink($snippet_file.'.org'); 60 | } 61 | $snippet_conv['rename'] = rename($snippet_file, $snippet_file.'.org'); 62 | } else { 63 | $snippet_conv['rename'] = false; 64 | } 65 | $fp = fopen($snippet_file, 'w'); 66 | if (!$fp) { 67 | $snippet_conv['update'] = false; 68 | } else { 69 | $snippet_conv['update'] = true; 70 | fwrite($fp, $snippet_conv['output']); 71 | fclose($fp); 72 | } 73 | } else { 74 | $snippet_conv['rename'] = false; 75 | $snippet_conv['update'] = false; 76 | } 77 | $snippet_show_details = true; 78 | 79 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/show_converted_file.php'); 80 | } 81 | } 82 | MySQLConverterTool_GUI_Snippets::load(dirname(__FILE__).'/snippets/footer.php'); 83 | -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/generic008.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_num_rows 3 | --FILE-- 4 | 77 | --EXPECT-EXT/MYSQL-OUTPUT-- 78 | SUCCESS: connect 79 | 80 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 81 | --EXPECT-EXT/MYSQLI-OUTPUT-- 82 | SUCCESS: connect 83 | FAILURE: expecting boolean value, got NULL value, [0] 84 | 85 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 86 | 59, E_NOTICE, Undefined variable: illegal_result_identifier 87 | 59, E_WARNING, mysqli_num_rows() expects parameter 1 to be mysqli_result, null given 88 | --EXPECT-CONVERTER-ERRORS-- 89 | 30, 32, 32, 37, 90 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/generic_boolean001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysqli_fetch_length 3 | --FILE-- 4 | 77 | --EXPECT-EXT/MYSQL-OUTPUT-- 78 | SUCCESS: connect 79 | 80 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 81 | --EXPECT-EXT/MYSQLI-OUTPUT-- 82 | SUCCESS: connect 83 | 84 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 85 | 57, E_NOTICE, Undefined variable: illegal_result_identifier 86 | 57, E_WARNING, mysqli_fetch_lengths() expects parameter 1 to be mysqli_result, null given 87 | --EXPECT-CONVERTER-ERRORS-- 88 | 26, 28, 28, 33, 89 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Converter/TestCode/free_result001.php: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SUCCESS: mysql_free_result 3 | --FILE-- 4 | 74 | --EXPECT-EXT/MYSQL-OUTPUT-- 75 | SUCCESS: connect 76 | 77 | --EXPECT-EXT/MYSQL-PHP-ERRORS-- 78 | --EXPECT-EXT/MYSQLI-OUTPUT-- 79 | SUCCESS: connect 80 | 81 | --EXPECT-EXT/MYSQLI-PHP-ERRORS-- 82 | 56, E_NOTICE, Undefined variable: illegal_result_identifier 83 | 56, E_WARNING, mysqli_free_result() expects parameter 1 to be mysqli_result, null given 84 | 56, E_NOTICE, Undefined variable: illegal_result_identifier 85 | --EXPECT-CONVERTER-ERRORS-- 86 | 28, 30, 30, 35, 87 | --ENDOFTEST-- -------------------------------------------------------------------------------- /UnitTests/Function/GenericTest.php: -------------------------------------------------------------------------------- 1 | , Ulf Wendel 15 | * @copyright 1997-2006 The PHP Group 16 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 17 | * 18 | * @version CVS: $Id:$, Release: @package_version@ 19 | * 20 | * @link http://www.mysql.com 21 | * @since Class available since Release 1.0 22 | */ 23 | class MySQLConverterTool_UnitTests_Function_GenericTest extends PHPUnit_Framework_TestCase 24 | { 25 | protected $default_conn = null; 26 | protected $gen = null; 27 | 28 | public static function main() 29 | { 30 | $suite = new PHPUnit_Framework_TestSuite('MySQLConverterTool_Function_GenericTest'); 31 | $result = PHPUnit_TextUI_TestRunner::run($suite); 32 | } 33 | 34 | /** 35 | * Sets up the fixture, for example, open a network connection. 36 | * This method is called before a test is executed. 37 | */ 38 | protected function setUp() 39 | { 40 | $this->gen = new MySQLConverterTool_Function_Generic('mysqli_query'); 41 | $this->default_conn = $this->gen->ston_name; 42 | } 43 | 44 | /** 45 | * Tears down the fixture, for example, close a network connection. 46 | * This method is called after a test is executed. 47 | */ 48 | protected function tearDown() 49 | { 50 | $this->gen = null; 51 | $this->default_conn = null; 52 | } 53 | 54 | /** 55 | * 56 | */ 57 | public function testSmart_concat() 58 | { 59 | $this->assertEquals('"A" . $B', $this->gen->smart_concat('A', '$B')); 60 | $this->assertEquals('"AB"', $this->gen->smart_concat('A', '"B"')); 61 | $this->assertEquals('"AB"', $this->gen->smart_concat('A', '"B"')); 62 | $this->assertEquals("'AB'", $this->gen->smart_concat('A', "'B'")); 63 | } 64 | 65 | public function testHandle() 66 | { 67 | list($warning, $code) = $this->gen->handle($this->buildParams(array('A', 'B'))); 68 | $this->assertNull($warning); 69 | $this->assertEquals('mysqli_query(A, B)', $code); 70 | } 71 | 72 | public function testGetConversionHint() 73 | { 74 | $this->assertNotEquals('', $this->gen->getConversionHint()); 75 | } 76 | 77 | public function testGetConversionPHPComment() 78 | { 79 | $this->assertNotEquals('', $this->gen->getConversionPHPComment()); 80 | } 81 | 82 | protected function buildParams(array $params, $dynamic = false) 83 | { 84 | $ret = array(); 85 | foreach ($params as $k => $param) { 86 | $ret[$k] = array('value' => $param, 'dynamic' => $dynamic); 87 | } 88 | 89 | return $ret; 90 | } 91 | } 92 | 93 | if (PHPUnit_MAIN_METHOD == 'MySQLConverterTool_Function_GenericTest::main') { 94 | MySQLConverterTool_Function_GenericTest::main(); 95 | } 96 | --------------------------------------------------------------------------------