<?php
function db_gettablelist()
{
	global $conn;
	$ret=array();
	$strSQL="select DATABASE() as dbname";
	$rs=db_query($strSQL,$conn);
	$data=db_fetch_array($rs);
	if(!$data)
		return $ret;
	$dbname=$data["dbname"];
	$query = db_query("SELECT VERSION() as mysqli_version",$conn);
	$data=db_fetch_array($query);
	$server_info=0;
	if($data)
		$server_info=$data["mysqli_version"];
	if($server_info>=5)
	{
		$strSQL="SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '".$dbname."'";
		$rs=db_query($strSQL,$conn);
		while($data=db_fetch_array($rs))
			$ret[]=$data["TABLE_NAME"];

		$strSQL="SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '".$dbname."'";
		$rs=db_query($strSQL,$conn);
		while($data=db_fetch_array($rs))
			if(!in_array($data["TABLE_NAME"],$ret))
				$ret[]=$data["TABLE_NAME"];
		sort($ret);
	}
	else
	{
		$strSQL="SHOW tables";
		$rs=db_query($strSQL,$conn);
		while($data=db_fetch_numarray($rs))
			$ret[]=$data[0];
	}
	
	return $ret;
}
function db_getfieldslist($strSQL)
{
	global $conn;
	$res=array();
	$rs = mysqli_query($conn, $strSQL);
	while($finfo = mysqli_fetch_field($rs)) 
	{
		$stype=db_fieldtypenum($finfo->type,$finfo->flags);
		$res[]=array("fieldname"=>$finfo->name,"type"=>$stype,"not_null"=>0);
	}
	$rs->close();
	return $res;
}
function db_fieldtypenum($stype,$flags)
{
	switch($stype)
	{
		case ($stype==0 || $stype==246):
			return 14;
		case ($stype==1 || $stype==2):
			return 2;
		case ($stype==3 || $stype==8 || $stype==9 || $stype==13):
			return 3;
		case ($stype==4 || $stype==5):
			return 5;
		case ($stype==7 || $stype==12 || $stype==14):
			return 135;
		case 10:
			return 7;
		case 11:
			return 134;
		case 253:
			return 200;
		case ($stype==247 || $stype==248):
			return 129;
		case ($stype==249 || $stype==250 || $stype==251 || $stype==252):
			if(is_numeric($flags) && $flags & 16 && $flags & 128 || strpos($flags,"binary")!==false)
				return 128;
			else
				return 201;
		case 254:
			return 129;
	}
	return 13;
}
?>