首页 > PHP

MySQL通用查询程序

时间:2009-05-07 17:19:32  作者:chinaitlab  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
if(get_magic_quotes_gpc()==1){
?>

MySQL通用查询程序

注意本程序需要将PHP配置文件(PHP3为php3.ini,PHP4为php.ini......
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("/","/",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>




如果您需转载 MySQL通用查询程序,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门