PHP篇——php访问Mysql数据库

$host = "localhost"; // 主机名或IP地址
$user = "root";       // MySQL用户名
$password = "xxx";           // MySQL密码
$dbname = "xxxx";         // 数据库名称
$mysqli=new mysqli($host,$user,$password,$dbname);
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: " . $mysqli->connect_error;
    exit;
} else {
    // 查询数据
    $result = $mysqli->query("SELECT * FROM user_table where username");
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            echo "username: " . $row["username"]. "
"; echo "password: " . $row["password"]. "

"; } } }

你可能感兴趣的:(PHP篇,MySql篇,数据库,php,mysql)