<?php
/*
SQLyog
Copyright 2003-2006, Webyog
http://www.webyog.com
HTTP Tunneling Page
This page exposes the MySQL API as a set of web-services which is consumed by SQLyog - the most popular GUI to MySQL.
This page allows SQLyog to manage MySQL even if the MySQL port is blocked or remote access to MySQL is not allowed.
*/
/*Wrapper Functions for PHP-MYSQL and PHP-MYSQLI*/
function yog_mysql_connect ($host, $port, $username, $password, $db_name="")
{
$username = utf8_decode($username);
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_connect ($host.':'.$port, $username, $password);
if (strlen ($db_name)!=0){
mysql_select_db("$db_name");
}
break;
case "mysqli":
$port=(int)$port;
$GLOBALS["___mysqli_ston"] = mysqli_connect($host, $username, $password,$db_name, $port);
$ret=$GLOBALS["___mysqli_ston"];
break;
}
return $ret;
}
function yog_mysql_field_type ( $result, $offset )
{
//Get the type of the specified field in a result
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_field_type ( $result, $offset );
break;
case "mysqli":
$tmp=mysqli_fetch_field_direct ( $result, $offset);
$ret = GetCorrectDataTypeMySQLI($tmp->type);
break;
}
return $ret;
}
function yog_mysql_field_len ( $result, $offset )
{
//Returns the length of the specified field
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_field_len ($result,$offset );
break;
case "mysqli":
$tmp=mysqli_fetch_field_direct ( $result, $offset);
$ret = $tmp->length;
break;
}
return $ret;
}
function yog_mysql_field_flags ($result, $offset)
{
//Get the flags associated with the specified field in a result
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_field_flags ($result,$offset);
break;
case "mysqli":
$___mysqli_obj = (mysqli_fetch_field_direct($result, $offset));
$___mysqli_tmp = $___mysqli_obj->flags;
$ret=($___mysqli_tmp? (string)(substr((($___mysqli_tmp & MYSQLI_NOT_NULL_FLAG) ? "not_null " : "") . (($___mysqli_tmp & MYSQLI_PRI_KEY_FLAG) ? "primary_key " : "") . (($___mysqli_tmp & MYSQLI_UNIQUE_KEY_FLAG) ? "unique_key " : "") . (($___mysqli_tmp & MYSQLI_MULTIPLE_KEY_FLAG) ? "unique_key " : "") . (($___mysqli_tmp & MYSQLI_BLOB_FLAG) ? "blob " : "") . (($___mysqli_tmp & MYSQLI_UNSIGNED_FLAG) ? "unsigned " : "") . (($___mysqli_tmp & MYSQLI_ZEROFILL_FLAG) ? "zerofill " : "") . (($___mysqli_tmp & 128) ? "binary " : "") . (($___mysqli_tmp & 256) ? "enum " : "") . (($___mysqli_tmp & MYSQLI_AUTO_INCREMENT_FLAG) ? "auto_increment " : "") . (($___mysqli_tmp & MYSQLI_TIMESTAMP_FLAG) ? "timestamp " : "") . (($___mysqli_tmp & MYSQLI_SET_FLAG) ? "set " : ""), 0, -1)) : false);
break;
}
return $ret;
}
function yog_mysql_get_server_info ($db_link)
{
//Get MySQL server info
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_get_server_info ($db_link);
break;
case "mysqli":
$ret = mysqli_get_server_info ($db_link);
break;
}
return $ret;
}
function yog_mysql_affected_rows ( $db_link )
{
//Get number of affected rows in previous MySQL operation
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_affected_rows($db_link);
break;
case "mysqli":
$ret = mysqli_affected_rows($db_link);
break;
}
return $ret;
}
function yog_mysql_insert_id ( $db_link )
{
//Get the ID generated from the previous INSERT operation
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_insert_id($db_link);
break;
case "mysqli":
$ret = mysqli_insert_id($db_link);
break;
}
return $ret;
}
function yog_mysql_query ( $query, $db_link )
{
//Send a MySQL query
$ret=array();
switch (DB_EXTENSION)
{
case "mysql":
$result = mysql_query ($query, $db_link);
/**********************/
if (yog_mysql_errno($db_link)!=0) {
$temp_ar= array("result"=>-1, "ar"=>mysql_affected_rows($db_link));
array_push($ret, $temp_ar);
}
elseif ($result===FALSE) {
$temp_ar= array("result"=>1, "ar"=>mysql_affected_rows($db_link));
array_push($ret, $temp_ar);
}
else {
$temp_ar= array("result"=>$result, "ar"=>mysql_affected_rows($db_link));
array_push($ret, $temp_ar);
}
/**********************/
break;
case "mysqli":
$ret = get_array_from_query($query, $db_link);
break;
}
return $ret;
}
function get_array_from_query($query, $db_link)
{
$ret=array();
$bool = mysqli_real_query ( $db_link, $query )or yog_mysql_error($db_link);
if (yog_mysql_errno($db_link)!=0) {
$temp_ar= array("result"=>-1, "ar"=>0);
array_push($ret, $temp_ar);
}
elseif ($bool) {
do {
/* store first result set */
$result = mysqli_store_result($db_link);
$num_ar= mysqli_affected_rows($db_link);
if ($result===FALSE && yog_mysql_errno($db_link)!=0) {
$temp_ar= array("result"=>-1, "ar"=>$num_ar);
array_push($ret, $temp_ar);
break;
}
elseif ($result===FALSE) {
$temp_ar= array("result"=>1, "ar"=>$num_ar);
array_push($ret, $temp_ar);
}
else {
$temp_ar= array("result"=>$result, "ar"=>$num_ar);
array_push($ret, $temp_ar);
}
} while (mysqli_next_result($db_link));
if (yog_mysql_errno($db_link)!=0) {
$temp_ar= array("result"=>-1, "ar"=>$num_ar);
array_push($ret, $temp_ar);
}
}
return $ret;
}
function yog_mysql_errno($db_link)
{
//Returns the numerical value of the error message from previous MySQL operation
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_errno($db_link);
break;
case "mysqli":
$ret = mysqli_errno($db_link);
break;
}
return $ret;
}
function yog_mysql_error($db_link)
{
//Returns the text of the error message from previous MySQL operation
$ret=0;
switch (DB_EXTENSION)
{
case "mysql":
$ret = mysql_error ($db_link);
break;
case