当前位置:Gxlcms > 数据库问题 > 选择指定的MySQL数据库

选择指定的MySQL数据库

时间:2021-07-01 10:21:17 帮助过:4人阅读

/******************************** *** 功能:选择指定的MySQL数据库 *********************************/ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>选择数据库</title> </head> <body background="image/bg.JPG"> <table align="center"><tr><td> <img src="image/banner.jpg"> </td></tr><tr><td background="image/head.JPG" align="center"> <form action="" method="post"> <select name="select"> <option value="1" selected="selected">请选择数据库</option> <!--连接数据库--> <?php $conn = mysql_connect("localhost","root",""); $rs = mysql_query("show databases");//查询操作 //将数据库名称以下拉列表的方式显示 while($rst = mysql_fetch_array($rs)){ $i = 0; echo "<option value = ".$rst[$i].">".$rst[$i]."</option>"; $i ++; } ?> </select> <input type="submit" name="sub" value="确定" /> </form> </td></tr><tr><td background="image/head.JPG"> <?php if(!empty($_POST["sub"])){ if($_POST["select"] == "1"){ echo "<script>alert(‘请选择数据库‘);</script>"; }else{ if(mysql_select_db($_POST["select"],$conn)){ echo "<script>alert(‘已经连接到指定的数据库‘);</script>"; mysql_close(); }else{ echo "<script>alert(‘出错了‘);</script>"; } } } ?> </td></tr></table> </body> </html>

 

选择指定的MySQL数据库

标签:

人气教程排行