欢迎来到代码驿站!

PHP代码

当前位置:首页 > 软件编程 > PHP代码

php实现的MySQL通用查询程序

时间:2021-02-04 11:34:43|栏目:PHP代码|点击:
if(get_magic_quotes_gpc()==1){
   ?>
<html>
<head><title>MySQL通用查询程序</title></head>
<body>
注意本程序需要将PHP配置文件(PHP3为php3.ini,PHP4为php.ini)中的magic_quotes_gpc
设成Off或0,修改后请重新启动Apache.
</body>
</html>
   <?
   exit();
}
set_magic_quotes_runtime(0);
$host = 'localhost';
$db = 'test';
$user = 'test';
$pass = '';
// [ php/inc/str2url.php ] cvs 1.2
function str2url($path){
   return eregi_replace("%2f","/",urlencode($path));
}
?>
<html>
<head><title>MySQL通用查询程序</title></head>
<body>
<form action="<?echo str2url($PHP_SELF);?>" method="post">
请输入SQL语句:<br>
<textarea name="sql" cols="100" rows="5"><?echo $sql;?></textarea><br>
<input type="submit" name="cmd" value="查询">
<input type="submit" name="cmd" value="执行">
</form>
<?
if($cmd){
   $con = mysql_pconnect($host,$user,$pass) or die('无法连接'.$host.'服务器');
   mysql_select_db($db,$con) or die('无法连接'.$db.'数据库');
   $rst = mysql_query($sql,$con) or die($sql.'出错');
   if($cmd=='查询'){
      $num_fields = mysql_num_fields($rst);
      echo '<hr>';
      echo '<table border="1" cellpadding="0" cellspacing="0">';
      echo '<caption align="center">'.$sql.'</option>';
      echo '<tr>';
      for($i=0;$i<$num_fields;$i++) echo '<th>&nbsp;'.mysql_field_name($rst,$i).'</th>';
      echo '</tr>';
      while($row=mysql_fetch_row($rst)){
         echo '<tr>';
         for($i=0;$i<$num_fields;$i++) echo '<td>&nbsp;'.$row[$i].'</td>';
         echo '</tr>';
      }
      echo '</table>';
      mysql_free_result($rst);
   }
   else echo '有 '.mysql_affected_rows($con).' 行受影响';
}
?>
</body>
</html>

上一篇:php inc文件使用的风险和注意事项

栏    目:PHP代码

下一篇:PHP Smarty模版简单使用方法

本文标题:php实现的MySQL通用查询程序

本文地址:http://www.codeinn.net/misctech/56755.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有