我正在嘗試使用PHP腳本從服務器獲取Status列的值。我收到以下錯誤:PHP SQl查詢中可捕獲的致命錯誤
<b>Catchable fatal error</b>: Object of class mysqli_result could not be converted to string in <b>C:\xampp\htdocs\loginstatuscheck.php</b> on line <b>21</b><br />
我對PHP腳本非常陌生。插入工作正常,在我嘗試執行提取查詢的同一行上。我現在的PHP腳本如下:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "iFocusBlogs";
$obtaineduserName = urldecode($_POST['enteredusername']);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query_get_status = "SELECT Status FROM LoginTable WHERE UserName ='" .$obtaineduserName. "'";
// perform the query and store the result
$result = $conn->query($query_get_status);
echo $result;
//if ($conn->query($query_get_status) === TRUE) {
// echo $result;
//} else {
echo "Error: " . $result . "<br>" . $conn->error;
//}
mysql_close();
$conn->close();
?>
請讓我知道我是正確的查詢和請讓我知道必須做讓我的查詢執行什麼樣的變化。所有建議都歡迎。提前致謝。
您無法echo $ result;這不是一個字符串嘗試print_r($結果)或var_dump ... –
'$ result'是一個對象,它不能被回顯爲字符串,除非類已經實現了'__toString'來顯示一些東西。 http://php.net/manual/en/language.oop5.magic.php#object.tostring –