PHP数据库操作
查询数据
<?php
$username = 'furong';
$con = mysql_connect("localhost", "root", "123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bank", $con);
$result = mysql_query("SELECT * FROM password where username = '$username'");
while($row = mysql_fetch_array($result))
{
echo $row['password'];
}
mysql_close($con);
?>
插入数据
<?php
$username = 'furong';
$password= '123456';
$con = mysql_connect("localhost", "root", "123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("bank", $con);
$result = mysql_query("insert into password values('$username', '$password')");
if(!$result)
{
echo 'failed';
}
else
{
echo 'success';
}
mysql_close($con);
?>