【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“connectnew.php”一文,供大家参考学习
<?
/*判断用户是否录入了用户名和口令,若是则接收用户输入,
否则取默认值即用户名和口令均为lxy*/
if (empty($username)) $username='lxy';
if (empty($password)) $password='lxy';
/*尝试进行MySQL数据库的连接*/
$id_link = @
mysql_connect('localhost',$username, $pass
word);
/* 如果连接失败,$id_link变量值为false,否则为true.*/
if (! $id_link) {?>
<!--连接失败,显示连接失败提示信息-->
<table>
<tr><td>
连接失败!
请在下面的表单中输入用户名和口令以便重新进行连接
</td></tr>
</table>
<!--接收用户名和口令输入的表单-->
<form action="connectnew.php" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" value="root"></td>
</tr>
<tr>
<td>口令:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="连接数据库">
</td>
</tr>
</table>
</form>
<? exit; } ?>
<p>连接成功!</p>