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

PHP
用 PHP5 轻松解析 XML
扩展你的 PHP 之入门篇
创造世界上最简单的 PHP 开发模式
特转载一高手总结PHP学习资源和链接.
PHP开发入门教程之面向对象
怎样才能成为PHP高手?学会“懒惰”的编程
详解:——如何将图片储存在数据库里
PHP生成静态页面详解
IIS6.0+PHP5.x+MySQL5.x+Zend3.0x+GD+phpMyAdmin2.8x通用安装实例(已经完成)
常用表单验证类,有了这个,一般的验证就都齐了。
PHP文件下载类
一个PHP日历程序
[转帖]PHP世纪万年历
PHP语法速查表
一些常用的php函数
PHP 开发工具
PHP 5.0 Pear安装方法
弄了个检测传输的参数是否为数字的Function
PHP一些有意思的小区别
一段防盗连的PHP代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 75 ::
收藏到网摘: 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>