File size: 4.33Kb
<?
/*
=============================================
Движок: SHCMS Engine
=============================================
Название файла: Запросы в базу данных
=============================================
Official website: http://shcms.ru
=============================================
*/
define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
$shcmsengine['title'] = 'SHCMS Engine Запросы в базу данных ';
include_once'../template/head.php';
registrat();
$adminka ->admin();
$user4 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id`='$user_id'"));
if($user4['team'] < 6)
{
echo 'Ошибка';
header('Refresh: 1; url=/index.php?'.$conservation.'&');
include_once'../template/foot.php';
exit();
}
include_once'secu.php';
echo '<div class="posts">Название вашей базы данных: <b>'.$user_db.'</b></div>';
if(isset($_GET['mysql_sql']) and $_GET['mysql_sql'] == 'sql' and isset($_POST['query']))
{
$sql = trim($_POST['query']);
if(empty($_POST['query'])){echo '<div class="mysql_no"><center>Вы не ввели запрос в базу данных</center></div>';header('Refresh: 1; url=?' . $conservation . '&' );exit();}
if($conf['phpversion'] ==5)
{
class MYSQL_Parser
{
static public function getQueriesFromFile( $file ){return self::getQueries( file_get_contents($file) );}
static public function getQueries( $sql )
{
$queries = array();
$strlen = strlen($sql);
$position = 0;
$query = '';
for ( ; $position < $strlen; ++$position )
{
$char = $sql{ $position };
switch ( $char )
{
case '-':
if ( substr($sql, $position, 3) !== '-- ' )
{
$query .= $char;
break;
}
case '#':
while ( $char !== "\r" && $char !== "\n" && $position < $strlen - 1 )
$char = $sql{ ++$position };
break;
case '`':
case '\'':
case '"':
$quote = $char;
$query .= $quote;
while ( $position < $strlen - 1 )
{
$char = $sql{ ++$position };
if ( $char === '\\' )
{
$query .= $char;
if ( $position < $strlen - 1 )
{
$char = $sql{ ++$position };
$query .= $char;
if ( $position < $strlen - 1 ) $char = $sql{ ++$position };
}
else
{
break;
}
}
if ( $char === $quote ) break;
$query .= $char;
}
$query .= $quote;
break;
case ';':
$query = trim($query);
if ( $query ) $queries[] = $query;
$query = '';
break;
default:
$query .= $char;
break;
}
}
$query = trim( $query );
if ( $query ) $queries[] = $query;
return $queries;}}
$sql = MYSQL_Parser::getQueries($sql);
}else{$sql = split(";(\n|\r)*",$sql);}
$k_z = 0; $k_z_ok = 0;
for($i=0;$i<count($sql);$i++)
{if($sql[$i] != ''){$k_z++;
if(mysql_query($sql[$i]))
{$k_z_ok++;}}}
if($k_z_ok > 0)
{if($k_z_ok == 1 and $k_z = 1)
echo '<div class="mysql_yes">Ваш запрос в базу данных успешно выполнен </div>';
else echo "<div class='mysql_yes'>Успешно выполнено запросов $k_z_ok из $k_z</div>";}}
echo "<form method=\"post\" action=\"?mysql_sql=sql&".$conservation."\">\n";
echo "<textarea name=\"query\" ></textarea><br />\n";
echo "<input value=\"Сделать запрос\" type=\"submit\" />\n";
echo "</form>\n";
include_once'../template/foot.php';
?>