当前位置: 首页 > 图文教程 > 网络编程 > PHP > php实现的MySQL通用查询程序

PHP
关于时间计算的结总
一些PHP写的小东西
用缓存实现静态页面的测试
PHP数字格式化
echo, print, printf 和 sprintf 区别
让你的网站首页自动选择语言转跳
如何使用PHP往windows中添加用户
PHP产生随机字符串函数
同一空间绑定多个域名而实现访问不同页面的PHP代码
实现 win2003 下 mysql 数据库每天自动备份
eWebEditor v3.8 商业完整版 (PHP)
PHP中,文件上传
計算你開發的 PHP 程式大小
產生圖片隨機字串
数字转英文
ajax缓存问题解决途径
PHP字符函数大全
从网上搜到的phpwind 0day的代码
IIS下配置Php+Mysql+zend的图文教程
如何写php程序?

PHP 中的 php实现的MySQL通用查询程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 74 ::
收藏到网摘: n/a

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>