php实现的MySQL通用查询程序_php教程-查字典教程网
php实现的MySQL通用查询程序
php实现的MySQL通用查询程序
发布时间:2016-12-29 来源:查字典编辑
摘要:if(get_magic_quotes_gpc()==1){?>MySQL通用查询程序注意本程序需要将PHP配置文件(PHP3为php3.i...

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]cvs1.2

functionstr2url($path){

returneregi_replace("%2f","/",urlencode($path));

}

?>

<html>

<head><title>MySQL通用查询程序</title></head>

<body>

<formaction="<?echostr2url($PHP_SELF);?>"method="post">

请输入SQL语句:<br>

<textareaname="sql"cols="100"rows="5"><?echo$sql;?></textarea><br>

<inputtype="submit"name="cmd"value="查询">

<inputtype="submit"name="cmd"value="执行">

</form>

<?

if($cmd){

$con=mysql_pconnect($host,$user,$pass)ordie('无法连接'.$host.'服务器');

mysql_select_db($db,$con)ordie('无法连接'.$db.'数据库');

$rst=mysql_query($sql,$con)ordie($sql.'出错');

if($cmd=='查询'){

$num_fields=mysql_num_fields($rst);

echo'<hr>';

echo'<tableborder="1"cellpadding="0"cellspacing="0">';

echo'<captionalign="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);

}

elseecho'有'.mysql_affected_rows($con).'行受影响';

}

?>

</body>

</html>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类