<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_loginstate.php";
include "../admin_version.php";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>SQL高级操作</title>
<link rel="stylesheet" type="text/css" href="../images/style.css">
<link type="text/css" href="../images/alerts.css" rel="stylesheet" media="screen">
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script language="javascript" src="../js/jquery.js"></script>
<script language="javascript" src="../js/alerts.js"></script>
<script language="javascript">
$(document).ready(function(){
	$("#execu").click(function(){
		var sql=$("#sql").val();
		if (sql=="") {
			$("#sql").css("border","1px solid red");
			return false;}
		})
})
</script>
</head>
<body leftmargin="1" topmargin="0" marginwidth="0" marginheight="0">
<?php
SystemPer(10);
$action=SafeRequest("action","get");
switch($action){
	case 'exe':
		main();
		executeresult();
		break;
	default:
		main();
		break;
	}
?>
<div class="r_main">
      <div class="r_content">
          <div class="r_content_1">
<?php
function main(){
?>
<div class="container" id="cpcontainer">
<form  method="post" action="?action=exe" name="form1">
<table class="tb_style" width="98%" align="center"> 
    <tr>
    	<td class="td_title">SQL语句执行操作</td>
      </tr>
    <tr>
    	<td class="td_border" align="center">
         <textarea rows="5"  name="sql" id="sql" cols="80" ></textarea>
    	</td>
      </tr>
      <tr>  
        <td class="td_border" align="center">
   		 <input type="submit" class="rb1" id="execu" value="执行ＳＱＬ"> 
   		&nbsp;&nbsp;   <input type="reset" value="清除ＳＱＬ" class="rb1">
        </td>
    </tr>
</table>
</form></div>
<?php
}

function executeresult(){
	global $db;
	$n=0;
	$sql=SafeRequest("sql","post");
	$sql=stripslashes($sql);
	if(strtolower(substr($sql,0,6))=="select"){
		$isselect="true";
		}
	else{
		$isselect="false";
		}
	
?>

<?php
if($db->query($sql)){
	$num=mysql_affected_rows();
?>
<table class="tb_style" border="0" cellpadding="0" cellspacing="0" width="98" align="center">
	<?php
	if($isselect=="true"){
		$results=$db->query($sql);
		$rows=$db->fetch_array($results);
		 
	?>
    <tr> 
		<?php foreach($rows as $k=>$v){?>
        <td  class="td_title" height="30" nowrap>&nbsp;<?php echo $k?></td>
		<?php }
		
		?>
    </tr>
		<?php 
		$results=$db->query($sql);
		while($rows=$db->fetch_array($results)){?>
    <tr> 
		<?php 
		
		foreach( $rows as $k=>$v){
			?>
        <td  class="td_border" nowrap  height="25">&nbsp;<?php echo $v?></td>
        <?php }
		
		?>
	</tr>
	<?php
		}
	}
	else{
	?>
	<tr>
    	<td class="td_title" height="30">&nbsp;执行结果</td>
    </tr>
	<tr>
    	<td class="td_border" height="25">&nbsp;
        <?php echo $num?>条记录受影响。
        </td>
    </tr>
		<?php
	}
		?>
</table>
<?php	
	}//有结果
	else{
	?>
<table class="tb_style" cellpadding="0" cellspacing="0" border="0" width="98%" align="center">
    <tr>
        <td class="td_title" width="50">&nbsp;错误号</td>
        <td class="td_title"> 错误信息</td>
    </tr>
    <tr> 
        <td class="td_border"><?php echo mysql_errno()?></td>
        <td class="td_border"><?php echo mysql_error()?></td>
    </tr>
</table>
	<?php
	}
}
?>

<TABLE width="100%" align="center" cellspacing="1" class="tb_style">
<TR>
	<TD valign="top" class="td_title"><strong>&nbsp;<br>
	  常用语句对照<br>
	</strong><br>
	<p>&nbsp;<strong>1.查询数据</strong></p>
	<p>&nbsp;&nbsp; select * from s_video&nbsp;&nbsp; 查询所有数据</p>
	<p>&nbsp;&nbsp; select * from s_video where S_ID=1000&nbsp;&nbsp; 查询指定ID数据</p>
    <p>&nbsp;<strong>2.删除数据</strong></p>
    <p>&nbsp;&nbsp; delete  from s_video&nbsp;&nbsp; 删除所有数据</p>
	<p>&nbsp;&nbsp; delete  from s_video where S_ID=1000 &nbsp; 删除指定的第几条数据</p>
	<p>&nbsp;&nbsp; delete  from s_video where S_Author Like '%周星星%'&nbsp;&nbsp; 删除S_Author字段里有&quot;周星星&quot;的数据<br>
  &nbsp;</p>
	<p><strong>&nbsp;3.修改数据<br>
	  <br>
	&nbsp;&nbsp; </strong>update s_video set S_Hits=1&nbsp;&nbsp; 将所有S_Hits字段里的值修改成&quot;1&quot;
	  <br>
	  <br>
	  <strong>&nbsp;&nbsp; </strong>update s_video set S_Hits=1 where S_ID=1000&nbsp; 指定的第几条数据把S_Hits字段里的值修改成&quot;1&quot; <br>
	  <br>
	  &nbsp;</p>
	</TD>
</TR>
</TABLE>
</div>
</div>
</div>
</body>
</html>



