First upload
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
<?php // <ERRORS><ERROR><DESCRIPTION>Your testing server do not has support for PHP pages</DESCRIPTION></ERROR>\n</ERRORS>
|
||||
// version 1.3
|
||||
$debug_to_file = false;
|
||||
|
||||
if (isset($_POST['SQL'])) {
|
||||
if (strpos($_POST['SQL'],"b64:") === 0) {
|
||||
$_POST['SQL'] = base64_decode(substr($_POST['SQL'],4));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function log_messages($error_message){
|
||||
global $f, $debug_to_file;
|
||||
if ($debug_to_file === true){
|
||||
if (!isset($f)){
|
||||
@ini_set('display_errors', 1);
|
||||
@error_reporting(E_ALL);
|
||||
$f = @fopen('log.txt', 'a');
|
||||
}
|
||||
return @fwrite($f, $error_message."\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function create_error($error_msg = '', $line = -1){
|
||||
if ($error_msg != ''){
|
||||
return '<ERRORS><ERROR><DESCRIPTION>'.$error_msg.'</DESCRIPTION></ERROR></ERRORS>\n';
|
||||
}else{
|
||||
return '<ERRORS><ERROR><DESCRIPTION> Unidentified Connection Error at Line '.$line.'</DESCRIPTION></ERROR></ERRORS>\n';
|
||||
}
|
||||
}
|
||||
|
||||
log_messages("\n--------------------------------");
|
||||
// what parameters were sent ?!
|
||||
foreach($_POST as $key=>$value) {
|
||||
if (strtoupper($key) != 'PASSWORD'){
|
||||
log_messages('$_POST["'.$key.'"] = \''.$value."';");
|
||||
}
|
||||
}
|
||||
// We need these information only once when the test button is hit
|
||||
if (isset($_POST['opCode']) && $_POST['opCode'] == 'IsOpen' ){
|
||||
// What PHP version
|
||||
log_messages("\nPHP-Version: ".phpversion());
|
||||
// What OS System is running on
|
||||
log_messages('PHP-OS: '.PHP_OS);
|
||||
// How PHP is installed (CGI, ISAPI, FastCGI)
|
||||
// !!!! Major difference exists on these servers for $_ENV, $_SERVER
|
||||
log_messages('PHP-SAPI-NAME: '.php_sapi_name());
|
||||
// MySQL, mbstring modules are installed ?!
|
||||
log_messages('PHP-Extensions: '.var_export(get_loaded_extensions(),true));
|
||||
}
|
||||
|
||||
if(extension_loaded('mbstring'))
|
||||
{
|
||||
$acceptCharsetHeader = 'Accept-Charset: ' . mb_internal_encoding();
|
||||
header( $acceptCharsetHeader );
|
||||
$head = '<html><head><meta http-equiv=\'Content-Type\' content=\'text/html; charset=' . mb_http_output() . '\'></head>';
|
||||
echo $head;
|
||||
}else{
|
||||
echo '<html><head></head>';
|
||||
}
|
||||
|
||||
// Build connection object
|
||||
if (isset($_POST['Type']) && $_POST['Type'] == 'MYSQL')
|
||||
{
|
||||
require("./mysql.php");
|
||||
|
||||
$oConn = new MySqlConnection(@$_POST['ConnectionString'], @$_POST['Timeout'], @$_POST['Host'], @$_POST['Database'], @$_POST['UserName'], @$_POST['Password']);
|
||||
if (!isset($oConn) || $oConn == false){
|
||||
log_messages("\n".'MySQL Connection Object initialisation failed'."\n\n".@$error);
|
||||
}else{
|
||||
log_messages("\n".'MySQL Connection Object Created'."\n\n");
|
||||
}
|
||||
}else{
|
||||
$error=create_error('The files from the _mmServerScripts folder are for the server model PHP-MySQL. You try to connect to a database using a different server model '.@$_POST['Type'].".\n\nPlease remove this folder outside the Dreamweaver environment on both local and testing machines and try again.",__LINE__);
|
||||
log_messages("\nError Sent:\n\n\t".@$error."\n\n\n");
|
||||
echo $error.'</HTML>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Process opCode
|
||||
if (isset($oConn) && $oConn)
|
||||
{
|
||||
$oConn->Open();
|
||||
|
||||
if (!$oConn->isOpen) {
|
||||
if (isset($_POST["ConnectionString"])) {
|
||||
$findPW = preg_match("/pwd=(.*)/",$_POST["ConnectionString"],$foundPW);
|
||||
if ($findPW) {
|
||||
$oConn->password = substr($foundPW[1],0,strlen($foundPW[1])-1);
|
||||
$oConn->Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$oConn->isOpen) {
|
||||
$KnownKeys = array();
|
||||
$knownKeys[] = "ConnectionString";
|
||||
$knownKeys[] = "Timeout";
|
||||
$knownKeys[] = "Host";
|
||||
$knownKeys[] = "Database";
|
||||
$knownKeys[] = "UserName";
|
||||
$knownKeys[] = "Password";
|
||||
$knownKeys[] = "Type";
|
||||
$knownKeys[] = "SQL";
|
||||
$knownKeys[] = "opCode";
|
||||
$knownKeys[] = "TableName";
|
||||
$knownKeys[] = "MaxRows";
|
||||
$knownKeys[] = "ProcName";
|
||||
$knownKeys[] = "ExecProcName";
|
||||
$knownKeys[] = "ExecProcParameters";
|
||||
$knownKeys[] = "ProcName";
|
||||
$pw = $_POST["Password"];
|
||||
foreach ($_POST as $key=>$val) {
|
||||
if (!in_array($key,$knownKeys)) {
|
||||
$pw .= "&" . $val;
|
||||
}
|
||||
}
|
||||
$oConn->password = $pw;
|
||||
$oConn->Open();
|
||||
}
|
||||
|
||||
|
||||
if ($_POST['opCode'] == 'IsOpen'){
|
||||
$answer = $oConn->TestOpen();
|
||||
} elseif ($oConn->isOpen){
|
||||
|
||||
switch ($_POST['opCode']){
|
||||
case 'GetTables': $answer = $oConn->GetTables(@$_POST['Database']); break;
|
||||
case 'GetColsOfTable': $answer = $oConn->GetColumnsOfTable(@$_POST['TableName']); break;
|
||||
case 'ExecuteSQL': $answer = $oConn->ExecuteSQL(@$_POST['SQL'], @$_POST['MaxRows']); break;
|
||||
case 'GetODBCDSNs': $answer = $oConn->GetDatabaseList(); break;
|
||||
case 'SupportsProcedure': $answer = $oConn->SupportsProcedure(); break;
|
||||
case 'GetProviderTypes': $answer = $oConn->GetProviderTypes(); break;
|
||||
case 'GetViews': $answer = $oConn->GetViews(); break;
|
||||
case 'GetProcedures': $answer = $oConn->GetProcedures(); break;
|
||||
case 'GetParametersOfProcedure': $answer = $oConn->GetParametersOfProcedure(@$_POST['ProcName']); break;
|
||||
case 'ReturnsResultset': $answer = $oConn->ReturnsResultSet($_POST['RRProcName']); break;
|
||||
case 'ExecuteSP': $answer = $oConn->ExecuteSP(@$_POST['ExecProcName'], 0, @$_POST['ExecProcParameters']); break;
|
||||
case 'GetKeysOfTable': $answer = $oConn->GetPrimaryKeysOfTable(@$_POST['TableName']); break;
|
||||
default: $answer = create_error('The \''.$_POST['opCode'].'\' command is not supported.'); break;
|
||||
}
|
||||
} else {
|
||||
//file_put_contents("debug.txt",json_encode($oConn),FILE_APPEND);
|
||||
//file_put_contents("debug.txt",json_encode($_POST),FILE_APPEND);
|
||||
//file_put_contents("debug.txt","\nnot open",FILE_APPEND);
|
||||
}
|
||||
|
||||
$oConn->Close();
|
||||
}else{
|
||||
$answer = create_error('The Connection Module was not initialized properly for an unknown reason.');
|
||||
}
|
||||
|
||||
log_messages("\nAnswer From Database:\n\n\t".@$answer."\n\n\n");
|
||||
echo $answer;
|
||||
|
||||
echo '</html>';
|
||||
?>
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
// version 1.1
|
||||
ini_set("display_errors",1);
|
||||
if((function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) || (ini_get('magic_quotes_sybase') && ( strtolower(ini_get('magic_quotes_sybase')) != "off" ))) {
|
||||
foreach($_POST as $k => $v) {
|
||||
if (is_array($_POST[$k])) {
|
||||
foreach($_POST[$k] as $x => $y) {
|
||||
$_POST[$k][$x] = stripslashes($y);
|
||||
}
|
||||
} else {
|
||||
$_POST[$k] = stripslashes($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($_POST as $k => $v) {
|
||||
if (is_array($_POST[$k])) {
|
||||
foreach($_POST[$k] as $x => $y) {
|
||||
$_POST[$k][$x] = urldecode(base64_decode(stripslashes($y)));
|
||||
}
|
||||
} else {
|
||||
$_POST[$k] = urldecode(base64_decode(stripslashes($v)));
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_POST["od_in"]) || intval($_POST["od_in"]) != intval("@@RANDNUM@@")) die("<WADB_RESPONSE><WADB_ERROR code=\"1\"><![CDATA[No hacking, please. Your location has been logged and reported to the FBI. Please wait for the authorities to arrive.]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
if (!isset($_POST["ch_ew_y"]) || intval($_POST["ch_ew_y"]) != intval("@@TIMESTAMP@@")) die("<WADB_RESPONSE><WADB_ERROR code=\"2\"><![CDATA[No hacking, please. Your location has been logged and reported to the FBI. Please wait for the authorities to arrive.]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
$timestampExpires = intval("@@TSEXPIRES@@") / 1000;
|
||||
$presTime = (intval("@@TIMESTAMP@@") / 1000);
|
||||
$servTime = intval("@@SERVTIMESTAMP@@");
|
||||
if ($servTime && (time() - $timestampExpires) >= $servTime) die("<WADB_RESPONSE><WADB_ERROR code=\"3\"><![CDATA[No hacking, please. Your location has been logged and reported to the FBI. Please wait for the authorities to arrive.]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
|
||||
|
||||
$connectionText = $_POST['connection'];
|
||||
$host = $_POST['hostname'];
|
||||
$user = $_POST['username'];
|
||||
$pass = $_POST['password'];
|
||||
$database = $_POST['databasename'];
|
||||
|
||||
if (strlen($pass) == 1 && ord($_POST['password']) == 0) {
|
||||
$pass = NULL;
|
||||
}
|
||||
|
||||
if (!extension_loaded('mysqli')) {
|
||||
$connection = mysql_connect($host, $user, $pass, $database);
|
||||
mysql_select_db($database,$connection);
|
||||
} else {
|
||||
$connection = new mysqli($host, $user, $pass, $database);
|
||||
}
|
||||
//die($host ."\n". $user."\n". $pass."\n". $database);
|
||||
|
||||
if ($connection->connect_errno) {
|
||||
die("<WADB_RESPONSE><WADB_ERROR code=\"10\"><![CDATA[Failed to connect to MySQL: (" . $connection->connect_errno . ") " . $connection->connect_error ."]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
}
|
||||
|
||||
$_POST['action'] = ( (isset($_POST['action'])) ? $_POST['action'] : 'query' );
|
||||
$columnString = "";
|
||||
$valuesString = "";
|
||||
$conditionString = "";
|
||||
switch ($_POST['action']) {
|
||||
case "insert":
|
||||
if (isset($_POST['values'])) {
|
||||
$valuesString = $_POST['values'];
|
||||
if (is_array($valuesString)) {
|
||||
$valuesString = implode(", ", $valuesString);
|
||||
}
|
||||
}
|
||||
if (isset($_POST['conditions'])) {
|
||||
$conditionString = $_POST['conditions'];
|
||||
if (is_array($conditionString)) {
|
||||
$conditionString = implode(" AND ", $conditionString);
|
||||
}
|
||||
}
|
||||
//no break for columns string as the "query" case
|
||||
case "query":
|
||||
$columnString="*";
|
||||
if (isset($_POST['column'])) {
|
||||
$columnString = $_POST['column'];
|
||||
if (is_array($columnString)) {
|
||||
$columnString = implode(", ", $columnString);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "update":
|
||||
if (isset($_POST['values']) && isset($_POST['column'])) {
|
||||
$valuesString = $_POST['values'];
|
||||
$columnString = $_POST['column'];
|
||||
$fullString = "";
|
||||
if (is_array($valuesString) && is_array($columnString)) {
|
||||
for ($n=0; $n<sizeof($columnString); $n++) {
|
||||
$fullString .= ( ($n != 0) ? ", " : "" ) . $columnString[$n] . "=" . $valuesString[$n];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fullString = $columnString . "=" . $valuesString;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
//connect to database
|
||||
switch ($_POST['action']) {
|
||||
case "create":
|
||||
$db_query = $_POST['fullstatement'];
|
||||
break;
|
||||
case "sct":
|
||||
$db_query = "SHOW CREATE TABLE `" . $_POST['table'] . "`";
|
||||
break;
|
||||
case "drop":
|
||||
$db_query = "DROP TABLE `" . $_POST['table'] . "`";
|
||||
break;
|
||||
case "firstrow":
|
||||
$db_query = "SELECT * FROM `" . $_POST['table'] . "` LIMIT 1";
|
||||
$_POST['action'] = "query";
|
||||
break;
|
||||
case "insert":
|
||||
if (!$conditionString || trim(strval($conditionString)) == "") {
|
||||
$db_query = "INSERT INTO `" . $_POST['table'] . "` (" . $columnString . ") VALUES (" . $valuesString . ")";
|
||||
} else {
|
||||
$db_query = "INSERT INTO `" . $_POST['table'] . "` (" . $columnString . ") SELECT " . $valuesString . " FROM " . $_POST['table'] . " WHERE NOT EXISTS (SELECT " . $columnString . " FROM " . $_POST['table'] . " WHERE " . $conditionString . ") LIMIT 1";
|
||||
}
|
||||
break;
|
||||
case "update":
|
||||
$db_query = "UPDATE `" . $_POST['table'] . "` SET " . $fullString . "";
|
||||
if (isset($_POST['filter'])) {
|
||||
$db_query .= " " . $_POST['filter'];
|
||||
}
|
||||
break;
|
||||
case "dbinfo":
|
||||
$db_query = "SHOW FULL TABLES FROM `" . $_POST['databasename'] ."`";
|
||||
break;
|
||||
case "delete":
|
||||
$db_query = "DELETE FROM `" . $_POST['table'] . "`";
|
||||
if (isset($_POST['filter'])) {
|
||||
$db_query .= " " . $_POST['filter'];
|
||||
}
|
||||
break;
|
||||
case "query":
|
||||
default:
|
||||
$db_query = "SELECT ".$columnString." FROM `".$_POST['table'] . '` ';
|
||||
if (isset($_POST['filter'])) {
|
||||
$db_query .= " " . $_POST['filter'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
echo "<WADB_RESPONSE>\n"."\t<WADB_INFO connection=\"".urlencode($connectionText)."\">\n";
|
||||
if (isset($_POST['table'])) {
|
||||
echo "\t\t<WADB_TABLE><![CDATA[".$_POST['table']."]]></WADB_TABLE>\n";
|
||||
}
|
||||
echo "\t\t<WADB_COLSTR><![CDATA[".$columnString."]]></WADB_COLSTR>\n".
|
||||
"\t\t<WADB_VALSTR><![CDATA[".$valuesString."]]></WADB_VALSTR>\n";
|
||||
if (isset($_POST['filter'])) {
|
||||
echo "\t\t<WADB_FILTER><![CDATA[".$_POST['filter']."]]></WADB_FILTER>\n";
|
||||
}
|
||||
echo "\t\t<WADB_STATEMENT><![CDATA[".$db_query."]]></WADB_STATEMENT>\n"."\t</WADB_INFO>\n";
|
||||
if (!extension_loaded('mysqli')) {
|
||||
$dbcontent = mysql_query($db_query,$connection);
|
||||
} else {
|
||||
$dbcontent = $connection->query($db_query);
|
||||
}
|
||||
if ($connection->connect_errno) die("<WADB_RESPONSE><WADB_ERROR code=\"5\"><![CDATA[Failed to execute sql: (" . $connection->connect_errno . ") ".$db_query." : " . $connection->connect_error ."]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
|
||||
switch ($_POST['action']) {
|
||||
case "query":
|
||||
case "sct":
|
||||
|
||||
if (!extension_loaded('mysqli')) {
|
||||
while ($row_dbcontent = mysql_fetch_assoc($dbcontent)) {
|
||||
echo("\t<WADB_DATA>\n");
|
||||
foreach ($row_dbcontent as $key => $value) {
|
||||
echo('\t\t<WADB_COLUMN name="'.urlencode($key).'"><![CDATA['.$value."]]></WADB_COLUMN>\n");
|
||||
}
|
||||
echo("\t</WADB_DATA>\n");
|
||||
}
|
||||
mysql_free_result($dbcontent);
|
||||
} else {
|
||||
while ($row_dbcontent = mysqli_fetch_assoc($dbcontent)) {
|
||||
echo("\t<WADB_DATA>\n");
|
||||
foreach ($row_dbcontent as $key => $value) {
|
||||
echo('\t\t<WADB_COLUMN name="'.urlencode($key).'"><![CDATA['.$value."]]></WADB_COLUMN>\n");
|
||||
}
|
||||
echo("\t</WADB_DATA>\n");
|
||||
}
|
||||
mysqli_free_result($dbcontent);
|
||||
}
|
||||
break;
|
||||
case "dbinfo":
|
||||
if (extension_loaded('mysqli')) {
|
||||
while ($row_dbcontent = mysqli_fetch_assoc($dbcontent)) {
|
||||
echo("\t<WADB_DATA>\n");
|
||||
foreach ($row_dbcontent as $key => $value) {
|
||||
$dbcolcontent = $connection->query("SHOW COLUMNS FROM `" . $value . "`");
|
||||
if ($connection->connect_errno) die("<WADB_RESPONSE><WADB_ERROR code=\"5\"><![CDATA[Failed to execute sql: (" . $connection->connect_errno . ") ".$db_query." : " . $connection->connect_error ."]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
|
||||
$dballcols = array();
|
||||
if ($dbcolcontent) while ($row = $dbcolcontent->fetch_array()) {
|
||||
$dballcols[] = $row;
|
||||
}
|
||||
if ($dbcolcontent) mysqli_free_result($dbcolcontent);
|
||||
echo('\t\t<WADB_COLUMN name="'.urlencode($value).'"><![CDATA['.json_encode($dballcols)."]]></WADB_COLUMN>\n");
|
||||
break;
|
||||
}
|
||||
echo("\t</WADB_DATA>\n");
|
||||
}
|
||||
mysqli_free_result($dbcontent);
|
||||
} else {
|
||||
while ($row_dbcontent = mysql_fetch_assoc($dbcontent)) {
|
||||
echo("\t<WADB_DATA>\n");
|
||||
foreach ($row_dbcontent as $key => $value) {
|
||||
$dbcolcontent = mysql_query("SHOW COLUMNS FROM `" . $value . "`",$connection);
|
||||
if ($connection->connect_errno) die("<WADB_RESPONSE><WADB_ERROR code=\"5\"><![CDATA[Failed to execute sql: (" . $connection->connect_errno . ") ".$db_query." : " . $connection->connect_error ."]]></WADB_ERROR></WADB_RESPONSE>");
|
||||
$dballcols = mysql_fetch_all($dbcolcontent);
|
||||
mysql_free_result($dbcolcontent);
|
||||
echo('\t\t<WADB_COLUMN name="'.urlencode($value).'"><![CDATA['.json_encode($dballcols)."]]></WADB_COLUMN>\n");
|
||||
}
|
||||
echo("\t</WADB_DATA>\n");
|
||||
}
|
||||
mysql_free_result($dbcontent);
|
||||
}
|
||||
break;
|
||||
case "insert":
|
||||
if (extension_loaded('mysqli')) {
|
||||
echo("\t<WADB_DATA><![CDATA[".mysqli_insert_id($connection)."]]></WADB_DATA>\n");
|
||||
} else {
|
||||
echo("\t<WADB_DATA><![CDATA[".mysql_insert_id($connection)."]]></WADB_DATA>\n");
|
||||
}
|
||||
break;
|
||||
case "create":
|
||||
case "drop":
|
||||
case "update":
|
||||
default:
|
||||
echo("\t<WADB_DATA><![CDATA[success]]></WADB_DATA>\n");
|
||||
}
|
||||
echo "</WADB_RESPONSE>";
|
||||
?>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<dwsync>
|
||||
<file name="mysql.php" server="C:/Users/ray/AppData/Roaming/Adobe/Dreamweaver 2021/en_US/Configuration/" local="132736842893791433" remote="132736842890000000" Dst="2" />
|
||||
<file name="MMHTTPDB.php" server="C:/Users/ray/AppData/Roaming/Adobe/Dreamweaver 2021/en_US/Configuration/" local="132609175028197128" remote="132609175020000000" Dst="2" />
|
||||
<file name="WA_DBScript.php" server="C:/Users/ray/AppData/Roaming/Adobe/Dreamweaver 2021/en_US/Configuration/" local="132609175095240531" remote="132609175090000000" Dst="2" />
|
||||
<file name="MMHTTPDB.php" server="C:/xampp/htdocs/bookingsystem/" local="133360708719471381" remote="133360708710000000" Dst="2" />
|
||||
<file name="mysql.php" server="C:/xampp/htdocs/bookingsystem/" local="133360708719539792" remote="133360708710000000" Dst="2" />
|
||||
<file name="WA_DBScript.php" server="C:/xampp/htdocs/bookingsystem/" local="133360708719662624" remote="133360708710000000" Dst="2" />
|
||||
</dwsync>
|
||||
@@ -0,0 +1,928 @@
|
||||
<?php
|
||||
if (extension_loaded('mysqli')) {
|
||||
// If this file is not included from the MMHTTPDB possible hacking problem.
|
||||
if (!function_exists('create_error')){
|
||||
die();
|
||||
}
|
||||
ini_set("display_errors",1);
|
||||
define('CONN_NOT_OPEN_GET_TABLES', create_error('The Connection could not be opened when trying to retrieve the tables.'));
|
||||
define('CONN_NOT_OPEN_GET_DB_LIST', create_error('The Connection could not be opened when trying to retrieve the database list.'));
|
||||
|
||||
// Now let's handle the crashes or any other PHP errors that we can catch
|
||||
function KT_ErrorHandler($errno, $errstr, $errfile, $errline) {
|
||||
global $f, $already_sent;
|
||||
$errortype = array (
|
||||
1 => "Error",
|
||||
2 => "Warning",
|
||||
4 => "Parsing Error",
|
||||
8 => "Notice",
|
||||
16 => "Core Error",
|
||||
32 => "Core Warning",
|
||||
64 => "Compile Error",
|
||||
128 => "Compile Warning",
|
||||
256 => "User Error",
|
||||
512 => "User Warning",
|
||||
1024=> "User Notice",
|
||||
2048=> "E_ALL",
|
||||
2049=> "PHP5 E_STRICT"
|
||||
|
||||
);
|
||||
$str = sprintf("[%s]\n%s:\t%s\nFile:\t\t'%s'\nLine:\t\t%s\n\n", date('d-m-Y H:i:s'),(isset($errortype[@$errno])?$errortype[@$errno]:('Unknown '.$errno)),@$errstr,@$errfile,@$errline);
|
||||
if (error_reporting() != 0) {
|
||||
@fwrite($f, $str);
|
||||
if (@$errno == 2 && isset($already_sent) && !$already_sent==true){
|
||||
$error = '<ERRORS>'."\n";
|
||||
$error .= '<ERROR><DESCRIPTION>An Warning Type error appeared. The error is logged into the log file.</DESCRIPTION></ERROR>'."\n";
|
||||
$error .= '</ERRORS>'."\n";
|
||||
$already_sent = true;
|
||||
echo $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($debug_to_file){
|
||||
$old_error_handler = set_error_handler("KT_ErrorHandler");
|
||||
}
|
||||
|
||||
class MySqlConnection
|
||||
{
|
||||
/*
|
||||
// The 'var' keyword is deprecated in PHP5 ... we will define these variables at runtime.
|
||||
var $isOpen;
|
||||
var $hostname;
|
||||
var $database;
|
||||
var $username;
|
||||
var $password;
|
||||
var $timeout;
|
||||
var $connectionId;
|
||||
var $error;
|
||||
*/
|
||||
function __construct($ConnectionString, $Timeout, $Host, $DB, $UID, $Pwd)
|
||||
{
|
||||
$this->isOpen = false;
|
||||
$this->timeout = $Timeout;
|
||||
$this->error = '';
|
||||
|
||||
log_messages(json_encode($_POST));
|
||||
|
||||
if( $Host ) {
|
||||
$this->hostname = $Host;
|
||||
}
|
||||
elseif( preg_match("/host=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->hostname = $ret[1];
|
||||
}
|
||||
|
||||
if( $DB ) {
|
||||
$this->database = $DB;
|
||||
}
|
||||
elseif( preg_match("/db=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->database = $ret[1];
|
||||
}
|
||||
|
||||
if( $UID ) {
|
||||
$this->username = $UID;
|
||||
}
|
||||
elseif( preg_match("/uid=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->username = $ret[1];
|
||||
}
|
||||
|
||||
if( $Pwd ) {
|
||||
$this->password = $Pwd;
|
||||
}
|
||||
elseif( preg_match("/pwd=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->password = $ret[1];
|
||||
}
|
||||
}
|
||||
|
||||
function Open()
|
||||
{
|
||||
$this->connectionId = new mysqli($this->hostname, $this->username, $this->password, $this->database);
|
||||
if (mysqli_connect_errno())
|
||||
{
|
||||
$this->isOpen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->isOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
function TestOpen()
|
||||
{
|
||||
return ($this->isOpen) ? '<TEST status=true></TEST>' : $this->HandleException();
|
||||
}
|
||||
|
||||
function Close()
|
||||
{
|
||||
if ($this->isOpen)
|
||||
{
|
||||
$this->isOpen = false;
|
||||
$this->connectionId->close();
|
||||
}
|
||||
}
|
||||
|
||||
function GetTables($table_name = '')
|
||||
{
|
||||
$xmlOutput = "";
|
||||
if ($this->isOpen && isset($this->connectionId)){
|
||||
if ($table_name === ''){
|
||||
$table_name = @$_POST['Database'];
|
||||
}
|
||||
$sql = ' SHOW TABLES FROM ' . $this->ensureTicks($table_name) ;
|
||||
$results = $this->connectionId->query($sql) or $this->HandleException();
|
||||
|
||||
$xmlOutput = "<RESULTSET><FIELDS>";
|
||||
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>'; // column 0 (zero-based)
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>'; // column 1
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_NAME</NAME></FIELD>'; // column 2
|
||||
|
||||
$xmlOutput .= "</FIELDS><ROWS>";
|
||||
|
||||
|
||||
while ($row = $results->fetch_array()) {
|
||||
$xmlOutput .= '<ROW><VALUE/><VALUE/><VALUE>' . $row[0]. '</VALUE></ROW>';
|
||||
}
|
||||
$results->free();
|
||||
}
|
||||
|
||||
$xmlOutput .= "</ROWS></RESULTSET>";
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetViews()
|
||||
{
|
||||
// not supported
|
||||
return "<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
function GetProcedures()
|
||||
{
|
||||
// not supported
|
||||
return "<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
function GetColumnsOfTable($TableName)
|
||||
{
|
||||
$xmlOutput = "";
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
$query = "DESCRIBE ".$this->ensureTicks($TableName);
|
||||
$result = $this->connectionId->query($query) or $this->HandleException();
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$xmlOutput = "<RESULTSET><FIELDS>";
|
||||
|
||||
// Columns are referenced by index, so Schema and
|
||||
// Catalog must be specified even though they are not supported
|
||||
$xmlOutput .= "<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>"; // column 0 (zero-based)
|
||||
$xmlOutput .= "<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>"; // column 1
|
||||
$xmlOutput .= "<FIELD><NAME>TABLE_NAME</NAME></FIELD>"; // column 2
|
||||
$xmlOutput .= "<FIELD><NAME>COLUMN_NAME</NAME></FIELD>";
|
||||
$xmlOutput .= "<FIELD><NAME>DATA_TYPE</NAME></FIELD>";
|
||||
$xmlOutput .= "<FIELD><NAME>IS_NULLABLE</NAME></FIELD>";
|
||||
$xmlOutput .= "<FIELD><NAME>COLUMN_SIZE</NAME></FIELD>";
|
||||
|
||||
$xmlOutput .= "</FIELDS><ROWS>";
|
||||
|
||||
// The fields returned from DESCRIBE are: Field, Type, Null, Key, Default, Extra
|
||||
while ($row = $result->fetch_array(MYSQLI_ASSOC))
|
||||
{
|
||||
$xmlOutput .= "<ROW><VALUE/><VALUE/><VALUE/>";
|
||||
|
||||
// Separate type from size. Format is: type(size)
|
||||
if (preg_match("/(.*)\((.*)\)/", $row["Type"], $ret))
|
||||
{
|
||||
$type = $ret[1];
|
||||
$size = $ret[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = $row["Type"];
|
||||
$size = "";
|
||||
}
|
||||
|
||||
// MySQL sets nullable to "YES" or "", so we need to set "NO"
|
||||
$null = $row["Null"];
|
||||
if ($null == "")
|
||||
$null = "NO";
|
||||
|
||||
$xmlOutput .= "<VALUE>" . $row["Field"] . "</VALUE>";
|
||||
$xmlOutput .= "<VALUE>" . $type . "</VALUE>";
|
||||
$xmlOutput .= "<VALUE>" . $null . "</VALUE>";
|
||||
$xmlOutput .= "<VALUE>" . $size . "</VALUE></ROW>";
|
||||
}
|
||||
$result->free();
|
||||
|
||||
$xmlOutput .= "</ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetParametersOfProcedure($ProcedureName, $SchemaName, $CatalogName)
|
||||
{
|
||||
// not supported on MySQL
|
||||
return '<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
}
|
||||
|
||||
function ExecuteSQL($aStatement, $MaxRows)
|
||||
{
|
||||
log_messages("Statement: " . $aStatement);
|
||||
|
||||
if ($aStatement == "systime") return '<RESULTSET><FIELDS><FIELD><NAME>'.time().'</NAME></FIELD></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
|
||||
$xmlOutput = "";
|
||||
$result = $this->connectionId->query($aStatement) or $this->HandleException();
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$xmlOutput = "<RESULTSET><FIELDS>";
|
||||
|
||||
$fieldCount = $result->field_count;
|
||||
for ($i=0; $i < $fieldCount; $i++)
|
||||
{
|
||||
$meta = $result->fetch_field();
|
||||
if ($meta)
|
||||
{
|
||||
$xmlOutput .= '<FIELD';
|
||||
$xmlOutput .= ' type="' . $meta->type;
|
||||
$xmlOutput .= '" max_length="' . $meta->max_length;
|
||||
$xmlOutput .= '" table="' . $meta->table;
|
||||
$xmlOutput .= '" not_null="' . (($meta->flags & 1)?1:0);
|
||||
$xmlOutput .= '" numeric="' . (($meta->flags & 32768)?1:0);
|
||||
$xmlOutput .= '" unsigned="' . (($meta->flags & 32)?1:0);
|
||||
$xmlOutput .= '" zerofill="' . (($meta->flags & 64)?1:0);
|
||||
$xmlOutput .= '" primary_key="' . (($meta->flags & 2)?1:0);
|
||||
$xmlOutput .= '" multiple_key="'. (($meta->flags & 16384)?1:0);
|
||||
$xmlOutput .= '" unique_key="' . (($meta->flags & 4)?1:0);
|
||||
$xmlOutput .= '"><NAME>' . $meta->name;
|
||||
$xmlOutput .= '</NAME></FIELD>';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
numerics
|
||||
-------------
|
||||
BIT: 16
|
||||
TINYINT: 1
|
||||
BOOL: 1
|
||||
SMALLINT: 2
|
||||
MEDIUMINT: 9
|
||||
INTEGER: 3
|
||||
BIGINT: 8
|
||||
SERIAL: 8
|
||||
FLOAT: 4
|
||||
DOUBLE: 5
|
||||
DECIMAL: 246
|
||||
NUMERIC: 246
|
||||
FIXED: 246
|
||||
|
||||
dates
|
||||
------------
|
||||
DATE: 10
|
||||
DATETIME: 12
|
||||
TIMESTAMP: 7
|
||||
TIME: 11
|
||||
YEAR: 13
|
||||
|
||||
strings & binary
|
||||
------------
|
||||
CHAR: 254
|
||||
VARCHAR: 253
|
||||
ENUM: 254
|
||||
SET: 254
|
||||
BINARY: 254
|
||||
VARBINARY: 253
|
||||
TINYBLOB: 252
|
||||
BLOB: 252
|
||||
MEDIUMBLOB: 252
|
||||
TINYTEXT: 252
|
||||
TEXT: 252
|
||||
MEDIUMTEXT: 252
|
||||
LONGTEXT: 252
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
NOT_NULL_FLAG = 1
|
||||
PRI_KEY_FLAG = 2
|
||||
UNIQUE_KEY_FLAG = 4
|
||||
BLOB_FLAG = 16
|
||||
UNSIGNED_FLAG = 32
|
||||
ZEROFILL_FLAG = 64
|
||||
BINARY_FLAG = 128
|
||||
ENUM_FLAG = 256
|
||||
AUTO_INCREMENT_FLAG = 512
|
||||
TIMESTAMP_FLAG = 1024
|
||||
SET_FLAG = 2048
|
||||
NUM_FLAG = 32768
|
||||
PART_KEY_FLAG = 16384
|
||||
GROUP_FLAG = 32768
|
||||
UNIQUE_FLAG = 65536
|
||||
*/
|
||||
|
||||
$xmlOutput .= "</FIELDS><ROWS>";
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
for ($i=0; $row && ($i < $MaxRows); $i++)
|
||||
{
|
||||
$xmlOutput .= "<ROW>";
|
||||
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$xmlOutput .= "<VALUE>";
|
||||
$xmlOutput .= htmlspecialchars($value);
|
||||
$xmlOutput .= "</VALUE>";
|
||||
}
|
||||
|
||||
$xmlOutput .= "</ROW>";
|
||||
$row = $result->fetch_assoc();
|
||||
}
|
||||
|
||||
$result->free();
|
||||
|
||||
$xmlOutput .= "</ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetProviderTypes()
|
||||
{
|
||||
return '<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
}
|
||||
|
||||
function ExecuteSP($aProcStatement, $TimeOut, $Parameters)
|
||||
{
|
||||
return '<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
}
|
||||
|
||||
function ReturnsResultSet($ProcedureName)
|
||||
{
|
||||
return '<RETURNSRESULTSET status=false></RETURNSRESULTSET>';
|
||||
}
|
||||
|
||||
function SupportsProcedure()
|
||||
{
|
||||
return '<SUPPORTSPROCEDURE status=false></SUPPORTSPROCEDURE>';
|
||||
}
|
||||
|
||||
/*
|
||||
* HandleException added by InterAKT for ease in database translation answer
|
||||
*/
|
||||
function HandleException()
|
||||
{
|
||||
global $debug_to_file, $f;
|
||||
$connectionError = $this->connectionId->connect_error;
|
||||
if ($connectionError) {
|
||||
$this->error = create_error(' MySQLi Connection Error#: '. $connectionError);
|
||||
} else {
|
||||
$this->error = create_error(' MySQLi Error#: '. ((int)mysqli_errno($this->connectionId)) . "\n\n".mysqli_error($this->connectionId));
|
||||
}
|
||||
log_messages($this->error);
|
||||
die($this->error.'</HTML>');
|
||||
}
|
||||
|
||||
function ensureTicks($inputSQL)
|
||||
{
|
||||
$outSQL = $inputSQL;
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
|
||||
//only add ticks if not already there
|
||||
$oLength = strlen($outSQL);
|
||||
$bHasTick = false;
|
||||
if (($oLength > 0) && (($outSQL[0] == "`") && ($outSQL[$oLength-1] == "`")))
|
||||
{
|
||||
$bHasTick = true;
|
||||
}
|
||||
if ($bHasTick == false)
|
||||
{
|
||||
$outSQL = "`".$outSQL."`";
|
||||
}
|
||||
return $outSQL;
|
||||
}
|
||||
|
||||
function GetDatabaseList()
|
||||
{
|
||||
$xmlOutput = '<RESULTSET><FIELDS><FIELD><NAME>NAME</NAME></FIELD></FIELDS><ROWS>';
|
||||
if ($this->isOpen){
|
||||
$dbList = $this->connectionId->query("SHOW DATABASES") or $this->HandleException();
|
||||
$row_getRS = $dbList->fetch_assoc();
|
||||
|
||||
while( $row = $dbList->fetch_row() ) {
|
||||
if (($row[0]!="information_schema") && ($row[0]!="mysql")) {
|
||||
$xmlOutput .= '<ROW><VALUE>' . $row[0] . '</VALUE></ROW>';
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$this->error = CONN_NOT_OPEN_GET_DB_LIST;
|
||||
return $this->error;
|
||||
}
|
||||
$xmlOutput .= '</ROWS></RESULTSET>';
|
||||
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetPrimaryKeysOfTable($TableName)
|
||||
{
|
||||
$xmlOutput = '';
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
$query = "DESCRIBE ".$this->ensureTicks($TableName);
|
||||
$result = $this->connectionId->query($query) or $this->HandleException();
|
||||
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$xmlOutput = '<RESULTSET><FIELDS>';
|
||||
|
||||
// Columns are referenced by index, so Schema and
|
||||
// Catalog must be specified even though they are not supported
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>'; // column 0 (zero-based)
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>'; // column 1
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_NAME</NAME></FIELD>'; // column 2
|
||||
$xmlOutput .= '<FIELD><NAME>COLUMN_NAME</NAME></FIELD>';
|
||||
$xmlOutput .= '<FIELD><NAME>DATA_TYPE</NAME></FIELD>';
|
||||
$xmlOutput .= '<FIELD><NAME>IS_NULLABLE</NAME></FIELD>';
|
||||
$xmlOutput .= '<FIELD><NAME>COLUMN_SIZE</NAME></FIELD>';
|
||||
|
||||
$xmlOutput .= '</FIELDS><ROWS>';
|
||||
|
||||
// The fields returned from DESCRIBE are: Field, Type, Null, Key, Default, Extra
|
||||
while ($row = $result->fetch_array(MYSQLI_ASSOC))
|
||||
{
|
||||
if (strtoupper($row['Key']) == 'PRI'){
|
||||
$xmlOutput .= '<ROW><VALUE/><VALUE/><VALUE/>';
|
||||
|
||||
// Separate type from size. Format is: type(size)
|
||||
if (preg_match("/(.*)\((.*)\)/", $row['Type'], $ret))
|
||||
{
|
||||
$type = $ret[1];
|
||||
$size = $ret[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = $row['Type'];
|
||||
$size = '';
|
||||
}
|
||||
|
||||
// MySQL sets nullable to "YES" or "", so we need to set "NO"
|
||||
$null = $row['Null'];
|
||||
if ($null == '')
|
||||
$null = 'NO';
|
||||
|
||||
$xmlOutput .= '<VALUE>' . $row['Field'] . '</VALUE>';
|
||||
$xmlOutput .= '<VALUE>' . $type . '</VALUE>';
|
||||
$xmlOutput .= '<VALUE>' . $null . '</VALUE>';
|
||||
$xmlOutput .= '<VALUE>' . $size . '</VALUE></ROW>';
|
||||
}
|
||||
}
|
||||
$result->free();
|
||||
|
||||
$xmlOutput .= '</ROWS></RESULTSET>';
|
||||
}
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
} // class MySqlConnection
|
||||
} else {
|
||||
// If this file is not included from the MMHTTPDB possible hacking problem.
|
||||
if (!function_exists('create_error')){
|
||||
die();
|
||||
}
|
||||
|
||||
define('MYSQL_NOT_EXISTS', create_error("Your PHP server doesn't have the MySQL or MySQLi module loaded or you can't use the mysql_(p)connect functions."));
|
||||
define('CONN_NOT_OPEN_GET_TABLES', create_error('The Connection could not be opened when trying to retrieve the tables.'));
|
||||
define('CONN_NOT_OPEN_GET_DB_LIST', create_error('The Connection could not be opened when trying to retrieve the database list.'));
|
||||
|
||||
if (!function_exists('mysql_connect') || !function_exists('mysql_pconnect') || !extension_loaded('mysql')){
|
||||
echo MYSQL_NOT_EXISTS;
|
||||
die();
|
||||
}
|
||||
|
||||
// Now let's handle the crashes or any other PHP errors that we can catch
|
||||
function KT_ErrorHandler($errno, $errstr, $errfile, $errline) {
|
||||
global $f, $already_sent;
|
||||
$errortype = array (
|
||||
1 => "Error",
|
||||
2 => "Warning",
|
||||
4 => "Parsing Error",
|
||||
8 => "Notice",
|
||||
16 => "Core Error",
|
||||
32 => "Core Warning",
|
||||
64 => "Compile Error",
|
||||
128 => "Compile Warning",
|
||||
256 => "User Error",
|
||||
512 => "User Warning",
|
||||
1024=> "User Notice",
|
||||
2048=> "E_ALL",
|
||||
2049=> "PHP5 E_STRICT"
|
||||
|
||||
);
|
||||
$str = sprintf("[%s]\n%s:\t%s\nFile:\t\t'%s'\nLine:\t\t%s\n\n", date('d-m-Y H:i:s'),(isset($errortype[@$errno])?$errortype[@$errno]:('Unknown '.$errno)),@$errstr,@$errfile,@$errline);
|
||||
if (error_reporting() != 0) {
|
||||
@fwrite($f, $str);
|
||||
if (@$errno == 2 && isset($already_sent) && !$already_sent==true){
|
||||
$error = '<ERRORS>'."\n";
|
||||
$error .= '<ERROR><DESCRIPTION>An Warning Type error appeared. The error is logged into the log file.</DESCRIPTION></ERROR>'."\n";
|
||||
$error .= '</ERRORS>'."\n";
|
||||
$already_sent = true;
|
||||
echo $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($debug_to_file){
|
||||
$old_error_handler = set_error_handler("KT_ErrorHandler");
|
||||
}
|
||||
|
||||
class MySqlConnection
|
||||
{
|
||||
/*
|
||||
// The 'var' keyword is deprecated in PHP5 ... we will define these variables at runtime.
|
||||
var $isOpen;
|
||||
var $hostname;
|
||||
var $database;
|
||||
var $username;
|
||||
var $password;
|
||||
var $timeout;
|
||||
var $connectionId;
|
||||
var $error;
|
||||
*/
|
||||
function __construct($ConnectionString, $Timeout, $Host, $DB, $UID, $Pwd)
|
||||
{
|
||||
$this->isOpen = false;
|
||||
$this->timeout = $Timeout;
|
||||
$this->error = '';
|
||||
|
||||
if( $Host ) {
|
||||
$this->hostname = $Host;
|
||||
}
|
||||
elseif( preg_match("/host=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->hostname = $ret[1];
|
||||
}
|
||||
|
||||
if( $DB ) {
|
||||
$this->database = $DB;
|
||||
}
|
||||
elseif( preg_match("/db=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->database = $ret[1];
|
||||
}
|
||||
|
||||
if( $UID ) {
|
||||
$this->username = $UID;
|
||||
}
|
||||
elseif( preg_match("/uid=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->username = $ret[1];
|
||||
}
|
||||
|
||||
if( $Pwd ) {
|
||||
$this->password = $Pwd;
|
||||
}
|
||||
elseif( preg_match("/pwd=([^;]+);/", $ConnectionString, $ret) ) {
|
||||
$this->password = $ret[1];
|
||||
}
|
||||
}
|
||||
|
||||
function Open()
|
||||
{
|
||||
$this->connectionId = mysql_connect($this->hostname, $this->username, $this->password);
|
||||
if (isset($this->connectionId) && $this->connectionId && is_resource($this->connectionId))
|
||||
{
|
||||
$this->isOpen = ($this->database == "") ? true : mysql_select_db($this->database, $this->connectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
function TestOpen()
|
||||
{
|
||||
return ($this->isOpen) ? '<TEST status=true></TEST>' : $this->HandleException();
|
||||
}
|
||||
|
||||
function Close()
|
||||
{
|
||||
if (is_resource($this->connectionId) && $this->isOpen)
|
||||
{
|
||||
if (mysql_close($this->connectionId))
|
||||
{
|
||||
$this->isOpen = false;
|
||||
unset($this->connectionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function GetTables($table_name = '')
|
||||
{
|
||||
$xmlOutput = "";
|
||||
if ($this->isOpen && isset($this->connectionId) && is_resource($this->connectionId)){
|
||||
// 1. mysql_list_tables and mysql_tablename are deprecated in PHP5
|
||||
// 2. For backward compatibility GetTables don't have any parameters
|
||||
if ($table_name === ''){
|
||||
$table_name = @$_POST['Database'];
|
||||
}
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
$sql = ' SHOW TABLES FROM ' . $this->ensureTicks($table_name) ;
|
||||
$results = mysql_query($sql, $this->connectionId) or $this->HandleException();
|
||||
|
||||
$xmlOutput = "<RESULTSET><FIELDS>";
|
||||
|
||||
// Columns are referenced by index, so Schema and
|
||||
// Catalog must be specified even though they are not supported
|
||||
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>'; // column 0 (zero-based)
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>'; // column 1
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_NAME</NAME></FIELD>'; // column 2
|
||||
|
||||
$xmlOutput .= "</FIELDS><ROWS>";
|
||||
|
||||
if (is_resource($results) && mysql_num_rows($results) > 0){
|
||||
while ($row = mysql_fetch_array($results)){
|
||||
$xmlOutput .= '<ROW><VALUE/><VALUE/><VALUE>' . $row[0]. '</VALUE></ROW>';
|
||||
}
|
||||
}
|
||||
$xmlOutput .= "</ROWS></RESULTSET>";
|
||||
|
||||
}
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetViews()
|
||||
{
|
||||
// not supported
|
||||
return "<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
function GetProcedures()
|
||||
{
|
||||
// not supported
|
||||
return "<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
function GetColumnsOfTable($TableName)
|
||||
{
|
||||
$xmlOutput = "";
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
$query = "DESCRIBE ".$this->ensureTicks($TableName);
|
||||
$result = mysql_query($query) or $this->HandleException();
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$xmlOutput = "<RESULTSET><FIELDS>";
|
||||
|
||||
// Columns are referenced by index, so Schema and
|
||||
// Catalog must be specified even though they are not supported
|
||||
$xmlOutput .= "<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>"; // column 0 (zero-based)
|
||||
$xmlOutput .= "<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>"; // column 1
|
||||
$xmlOutput .= "<FIELD><NAME>TABLE_NAME</NAME></FIELD>"; // column 2
|
||||
$xmlOutput .= "<FIELD><NAME>COLUMN_NAME</NAME></FIELD>";
|
||||
$xmlOutput .= "<FIELD><NAME>DATA_TYPE</NAME></FIELD>";
|
||||
$xmlOutput .= "<FIELD><NAME>IS_NULLABLE</NAME></FIELD>";
|
||||
$xmlOutput .= "<FIELD><NAME>COLUMN_SIZE</NAME></FIELD>";
|
||||
|
||||
$xmlOutput .= "</FIELDS><ROWS>";
|
||||
|
||||
// The fields returned from DESCRIBE are: Field, Type, Null, Key, Default, Extra
|
||||
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
|
||||
{
|
||||
$xmlOutput .= "<ROW><VALUE/><VALUE/><VALUE/>";
|
||||
|
||||
// Separate type from size. Format is: type(size)
|
||||
if (preg_match("/(.*)\((.*)\)/", $row["Type"], $ret))
|
||||
{
|
||||
$type = $ret[1];
|
||||
$size = $ret[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = $row["Type"];
|
||||
$size = "";
|
||||
}
|
||||
|
||||
// MySQL sets nullable to "YES" or "", so we need to set "NO"
|
||||
$null = $row["Null"];
|
||||
if ($null == "")
|
||||
$null = "NO";
|
||||
|
||||
$xmlOutput .= "<VALUE>" . $row["Field"] . "</VALUE>";
|
||||
$xmlOutput .= "<VALUE>" . $type . "</VALUE>";
|
||||
$xmlOutput .= "<VALUE>" . $null . "</VALUE>";
|
||||
$xmlOutput .= "<VALUE>" . $size . "</VALUE></ROW>";
|
||||
}
|
||||
mysql_free_result($result);
|
||||
|
||||
$xmlOutput .= "</ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetParametersOfProcedure($ProcedureName, $SchemaName, $CatalogName)
|
||||
{
|
||||
// not supported on MySQL
|
||||
return '<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
}
|
||||
|
||||
function ExecuteSQL($aStatement, $MaxRows)
|
||||
{
|
||||
|
||||
if ($aStatement == "systime") return '<RESULTSET><FIELDS><FIELD><NAME>'.time().'</NAME></FIELD></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
|
||||
$xmlOutput = "";
|
||||
|
||||
$result = mysql_query($aStatement) or $this->HandleException();
|
||||
|
||||
if (isset($result) && is_resource($result))
|
||||
{
|
||||
$xmlOutput = "<RESULTSET><FIELDS>";
|
||||
|
||||
$fieldCount = mysql_num_fields($result);
|
||||
for ($i=0; $i < $fieldCount; $i++)
|
||||
{
|
||||
$meta = mysql_fetch_field($result);
|
||||
if ($meta)
|
||||
{
|
||||
$xmlOutput .= '<FIELD';
|
||||
$xmlOutput .= ' type="' . $meta->type;
|
||||
$xmlOutput .= '" max_length="' . $meta->max_length;
|
||||
$xmlOutput .= '" table="' . $meta->table;
|
||||
$xmlOutput .= '" not_null="' . $meta->not_null;
|
||||
$xmlOutput .= '" numeric="' . $meta->numeric;
|
||||
$xmlOutput .= '" unsigned="' . $meta->unsigned;
|
||||
$xmlOutput .= '" zerofill="' . $meta->zerofill;
|
||||
$xmlOutput .= '" primary_key="' . $meta->primary_key;
|
||||
$xmlOutput .= '" multiple_key="'. $meta->multiple_key;
|
||||
$xmlOutput .= '" unique_key="' . $meta->unique_key;
|
||||
$xmlOutput .= '"><NAME>' . $meta->name;
|
||||
$xmlOutput .= '</NAME></FIELD>';
|
||||
}
|
||||
}
|
||||
|
||||
$xmlOutput .= "</FIELDS><ROWS>";
|
||||
$row = mysql_fetch_assoc($result);
|
||||
|
||||
for ($i=0; $row && ($i < $MaxRows); $i++)
|
||||
{
|
||||
$xmlOutput .= "<ROW>";
|
||||
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$xmlOutput .= "<VALUE>";
|
||||
$xmlOutput .= htmlspecialchars($value);
|
||||
$xmlOutput .= "</VALUE>";
|
||||
}
|
||||
|
||||
$xmlOutput .= "</ROW>";
|
||||
$row = mysql_fetch_assoc($result);
|
||||
}
|
||||
|
||||
mysql_free_result($result);
|
||||
|
||||
$xmlOutput .= "</ROWS></RESULTSET>";
|
||||
}
|
||||
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetProviderTypes()
|
||||
{
|
||||
return '<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
}
|
||||
|
||||
function ExecuteSP($aProcStatement, $TimeOut, $Parameters)
|
||||
{
|
||||
return '<RESULTSET><FIELDS></FIELDS><ROWS></ROWS></RESULTSET>';
|
||||
}
|
||||
|
||||
function ReturnsResultSet($ProcedureName)
|
||||
{
|
||||
return '<RETURNSRESULTSET status=false></RETURNSRESULTSET>';
|
||||
}
|
||||
|
||||
function SupportsProcedure()
|
||||
{
|
||||
return '<SUPPORTSPROCEDURE status=false></SUPPORTSPROCEDURE>';
|
||||
}
|
||||
|
||||
/*
|
||||
* HandleException added by InterAKT for ease in database translation answer
|
||||
*/
|
||||
function HandleException()
|
||||
{
|
||||
global $debug_to_file, $f;
|
||||
$this->error = create_error(' MySQL Error#: '. ((int)mysql_errno()) . "\n\n".mysql_error());
|
||||
log_messages($this->error);
|
||||
die($this->error.'</HTML>');
|
||||
}
|
||||
|
||||
function ensureTicks($inputSQL)
|
||||
{
|
||||
$outSQL = $inputSQL;
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
|
||||
//only add ticks if not already there
|
||||
$oLength = strlen($outSQL);
|
||||
$bHasTick = false;
|
||||
if (($oLength > 0) && (($outSQL[0] == "`") && ($outSQL[$oLength-1] == "`")))
|
||||
{
|
||||
$bHasTick = true;
|
||||
}
|
||||
if ($bHasTick == false)
|
||||
{
|
||||
$outSQL = "`".$outSQL."`";
|
||||
}
|
||||
return $outSQL;
|
||||
}
|
||||
|
||||
function GetDatabaseList()
|
||||
{
|
||||
$xmlOutput = '<RESULTSET><FIELDS><FIELD><NAME>NAME</NAME></FIELD></FIELDS><ROWS>';
|
||||
|
||||
if (isset($this->connectionId) && is_resource($this->connectionId)){
|
||||
$dbList = mysql_list_dbs($this->connectionId);
|
||||
|
||||
while ($row = mysql_fetch_object($dbList))
|
||||
{
|
||||
$xmlOutput .= '<ROW><VALUE>' . $row->Database . '</VALUE></ROW>';
|
||||
}
|
||||
}else{
|
||||
$this->error = CONN_NOT_OPEN_GET_DB_LIST;
|
||||
return $this->error;
|
||||
}
|
||||
$xmlOutput .= '</ROWS></RESULTSET>';
|
||||
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
function GetPrimaryKeysOfTable($TableName)
|
||||
{
|
||||
$xmlOutput = '';
|
||||
//added backtick for handling reserved words and special characters
|
||||
//http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
|
||||
$query = "DESCRIBE ".$this->ensureTicks($TableName);
|
||||
$result = mysql_query($query) or $this->HandleException();
|
||||
|
||||
|
||||
if ($result)
|
||||
{
|
||||
$xmlOutput = '<RESULTSET><FIELDS>';
|
||||
|
||||
// Columns are referenced by index, so Schema and
|
||||
// Catalog must be specified even though they are not supported
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_CATALOG</NAME></FIELD>'; // column 0 (zero-based)
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_SCHEMA</NAME></FIELD>'; // column 1
|
||||
$xmlOutput .= '<FIELD><NAME>TABLE_NAME</NAME></FIELD>'; // column 2
|
||||
$xmlOutput .= '<FIELD><NAME>COLUMN_NAME</NAME></FIELD>';
|
||||
$xmlOutput .= '<FIELD><NAME>DATA_TYPE</NAME></FIELD>';
|
||||
$xmlOutput .= '<FIELD><NAME>IS_NULLABLE</NAME></FIELD>';
|
||||
$xmlOutput .= '<FIELD><NAME>COLUMN_SIZE</NAME></FIELD>';
|
||||
|
||||
$xmlOutput .= '</FIELDS><ROWS>';
|
||||
|
||||
// The fields returned from DESCRIBE are: Field, Type, Null, Key, Default, Extra
|
||||
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
|
||||
{
|
||||
if (strtoupper($row['Key']) == 'PRI'){
|
||||
$xmlOutput .= '<ROW><VALUE/><VALUE/><VALUE/>';
|
||||
|
||||
// Separate type from size. Format is: type(size)
|
||||
if (preg_match("/(.*)\((.*)\)/", $row['Type'], $ret))
|
||||
{
|
||||
$type = $ret[1];
|
||||
$size = $ret[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = $row['Type'];
|
||||
$size = '';
|
||||
}
|
||||
|
||||
// MySQL sets nullable to "YES" or "", so we need to set "NO"
|
||||
$null = $row['Null'];
|
||||
if ($null == '')
|
||||
$null = 'NO';
|
||||
|
||||
$xmlOutput .= '<VALUE>' . $row['Field'] . '</VALUE>';
|
||||
$xmlOutput .= '<VALUE>' . $type . '</VALUE>';
|
||||
$xmlOutput .= '<VALUE>' . $null . '</VALUE>';
|
||||
$xmlOutput .= '<VALUE>' . $size . '</VALUE></ROW>';
|
||||
}
|
||||
}
|
||||
mysql_free_result($result);
|
||||
|
||||
$xmlOutput .= '</ROWS></RESULTSET>';
|
||||
}
|
||||
return $xmlOutput;
|
||||
}
|
||||
|
||||
} // class MySqlConnection
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user