我真的需要你的幫助。我已經看到答案,甚至遵循以前發佈的建議,但沒有解決方案顯示如何使用獲取關聯數組使用PREPARED STATEMENTS
,所以我不想提交已經回答的問題。我按照建議給別人的問題,但我仍然得到:致命錯誤與函數內fetch_assoc
Fatal error: Call to a member function fetch_assoc() on a non-object in /xxx/xxxxxx.php on line 75
我使用MySQL的展示你的舊代碼,我是如何改變了它用準備好的發言mysqli的,但我仍然得到同樣的致命錯誤。有人可以幫助我,我瘋了,我真的需要找出我做錯了什麼。謝謝你的幫助。
//*******************************************************************
// OLD CODE:
// Called by: $theme=$log->get_theme();
//*******************************************************************
class redirect
{
function __construct()
{
}
function get_theme()
{
$rs=mysql_query("select * from theme where status='yes'");
if(mysql_num_rows($rs)>0)
{
$data=mysql_fetch_array($rs);
return $data['theme_name'];
}
}
}
//*********************************************************************
// OLD CODE:
// Called by: $theme=$log->get_theme($cn);
//*********************************************************************
class redirect
{
public $cn;
function __construct()
{
}
function get_theme($cn)
{
$themeStatus = 'yes';
if ($stmt = $cn->prepare("SELECT * FROM theme WHERE status = ? "))
{
$stmt->bind_param("s", $themeStatus);
$result = $stmt->execute();
$stmt->store_result();
if ($stmt->num_rows >= "1")
{
$data = $result->fetch_assoc(); // ERROR LINE
return $data['theme_name'];
}
}
else
{
echo "Failed to execute prepared statement: " . mysqli_connect_error();
}
}
}
'$ cn'是如何應用的?我的意思是當你使用這個課程時你如何設置它? – Rasclatt
另外'public $ cn;'在你的代碼的這一點上是不相關的,因爲你沒有像'$ this-> cn = $ cn那樣指定它;'你現在怎麼擁有它,你不需要'public $ cn;' – Rasclatt
我正在像這樣使用它:\t \t $ log = new redirect(); $ thm = $ log-> get_theme($ cn); – TPdeveloper