MySQL通用查询程序


if(get_magic_quotes_gpc()==1){

?>

1<html>
2<head><title>MySQL通用查询程序</title></head>
3<body>   
4  
5注意本程序需要将PHP配置文件(PHP3为php3.ini,PHP4为php.ini)中的magic_quotes_gpc设成Off或0,修改后请重新启动Apache.   
6  
7</body>
8</html>
 1<html>
 2<head><title>MySQL通用查询程序</title></head>
 3<body>
 4<form action="&lt;?echo str2url($PHP_SELF);?&gt;" method="post">   
 5  
 6请输入SQL语句:<br/>
 7<textarea cols="100" name="sql" rows="5"><?echo $sql;?></textarea><br/>
 8<input name="cmd" type="submit" value="查询"/>
 9<input name="cmd" type="submit" value="执行"/>
10</form>
11<?   
12  
13if($cmd){   
14  
15$con = mysql_pconnect($host,$user,$pass) or die('无法连接'.$host.'服务器');   
16  
17mysql_select_db($db,$con) or die('无法连接'.$db.'数据库');   
18  
19$rst = mysql_query($sql,$con) or die($sql.'出错');   
20  
21if($cmd=='查询'){   
22  
23$num_fields = mysql_num_fields($rst);   
24  
25echo '<hr>';   
26  
27echo '<table border="1" cellpadding="0" cellspacing="0">';   
28  
29echo '<caption align="center">'.$sql.'';   
30  
31echo '<tr>';   
32  
33for($i=0;$i&lt;$num_fields;$i++) echo '<th> '.mysql_field_name($rst,$i).'</th>';   
34  
35echo '</tr>';   
36  
37while($row=mysql_fetch_row($rst)){   
38  
39echo '<tr>';   
40  
41for($i=0;$i&lt;$num_fields;$i++) echo '<td> '.$row[$i].'</td>';   
42  
43echo '</tr>';   
44  
45}   
46  
47echo '</caption></table>';   
48  
49mysql_free_result($rst);   
50  
51}   
52  
53else echo '有 '.mysql_affected_rows($con).' 行受影响';   
54  
55}   
56  
57?&gt;   
58  
59</body>
60</html>
Published At
Categories with 数据库类
comments powered by Disqus