php实现的MySQL通用查询程序

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

php实现的MySQL通用查询程序

  2021-03-17 我要评论
想了解php实现的MySQL通用查询程序的相关内容吗,在本文为您仔细讲解的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php实现的MySQL通用查询程序,下面大家一起来学习吧。
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> '.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> '.$row[$i].'</td>';
         echo '</tr>';
      }
      echo '</table>';
      mysql_free_result($rst);
   }
   else echo '有 '.mysql_affected_rows($con).' 行受影响';
}
?>
</body>
</html>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们