如何从PHP中的数据库中获取单个数字

时间:2016-06-05 17:31:26

标签: php mysql sql database echo

我需要回显数字10数据库中的数据库。我似乎无法让它工作。我在做什么错误的互联网人?

Picture of the database

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testfp";
$conn = new mysqli($servername, $username, $password, $dbname);


$sql = "SELECT hookup FROM testfp WHERE name = 100100" ;
$bob = mysql_query($sql);
echo $bob;
?>

1 个答案:

答案 0 :(得分:0)

您不能同时使用 mysql mysqli 。所以你可以尝试下面的代码(仅使用mysqli,因为不推荐使用mysql):

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testfp";
$conn = new mysqli($servername, $username, $password, $dbname);
//Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT hookup FROM testfp WHERE name = 100100" ;
$result = $conn->query($sql);
if($result->num_rows>0)
{
    while($row = $result->fetch_assoc()) {
        echo $row["hookup"];
    }
}
else
{
    echo "No results found!";
}
?>