php 无法 select 数据
php unable to select data
我正在尝试 select 来自 mysql 数据库的单个值。我在 phpmyadmin 中有 运行 查询,效果很好。但是当我回显 $result 时,我什么也得不到...顺便说一下,我使用 xxx 作为数据库和密码,因为我不想显示它...我的插入查询工作得很好
谢谢
<?php
//Create Connection
$servername = "localhost";
$username = "root";
$password = "xxx";
$dbname = "xxx";
//Connect
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT StartPriceUnder FROM YJ_Value";
$result = $conn->query($sql);
echo hi;
echo $result;
echo ya;
$conn->close();
?>
你必须获取你的结果,所以做这样的事情:
$row = $result->fetch_array(MYSQLI_ASSOC);
之后你可以像这样回显它:
echo $row["StartPriceUnder"];
有关 fetch_array()
的更多信息,请参阅手册:http://php.net/manual/en/mysqli-result.fetch-array.php
试试这个:
<?php
$servername = "localhost";
$username = "root";
$password = "xxx";
$dbname = "xxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT StartPriceUnder FROM YJ_Value";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "StartPriceUnder:" . $row["StartPriceUnder"];
}
}
else {
echo "0 results";
}
$conn->close();
?>
我正在尝试 select 来自 mysql 数据库的单个值。我在 phpmyadmin 中有 运行 查询,效果很好。但是当我回显 $result 时,我什么也得不到...顺便说一下,我使用 xxx 作为数据库和密码,因为我不想显示它...我的插入查询工作得很好
谢谢
<?php
//Create Connection
$servername = "localhost";
$username = "root";
$password = "xxx";
$dbname = "xxx";
//Connect
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT StartPriceUnder FROM YJ_Value";
$result = $conn->query($sql);
echo hi;
echo $result;
echo ya;
$conn->close();
?>
你必须获取你的结果,所以做这样的事情:
$row = $result->fetch_array(MYSQLI_ASSOC);
之后你可以像这样回显它:
echo $row["StartPriceUnder"];
有关 fetch_array()
的更多信息,请参阅手册:http://php.net/manual/en/mysqli-result.fetch-array.php
试试这个:
<?php
$servername = "localhost";
$username = "root";
$password = "xxx";
$dbname = "xxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT StartPriceUnder FROM YJ_Value";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "StartPriceUnder:" . $row["StartPriceUnder"];
}
}
else {
echo "0 results";
}
$conn->close();
?>