我很新,所以我找不出要使用的代碼。我想從SQL問題中獲得一個對象,這樣我就可以使用$ thePerson-> FirstName等獲取數據。PHP:從一個函數獲取mysql數據作爲對象
我打電話的功能,因爲這:
$thePerson = getPerson(1);
,這是功能至今:
function getPerson ($person) {
global $con;
$stmt = $con->prepare("SELECT * FROM personal WHERE IDA=?");
$stmt -> bind_param('i', $person);
$result = $stmt -> execute();
$theData = mysqli_fetch_object($result);
$stmt -> close();
return $theData;
}
我真的可以使用一些幫助改變代碼,所以它的工作原理。
那麼最新的問題?你有沒有試過'echo $ thePerson-> FirstName'? – Ghost 2014-10-30 08:54:26
「警告:mysqli_fetch_object()期望參數1是mysqli_result,布爾給定」是從數據庫選擇部分的錯誤,然後我得到「注意:嘗試獲取非對象的屬性」如果我嘗試「echo $ thePerson- > FirstName「 – 2014-10-30 10:01:11