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);

?>
posted @ 2018-08-23 15:32  thomas_blog  阅读(100)  评论(0编辑  收藏  举报