我在UPDATE語句中遇到了一個問題,無處不在,在這裏通過問題瀏覽,語法看起來是正確的,我錯過了什麼?PHP中UPDATE語句準備問題
$update_page = $db->stmt_init();
$update_page = $db->prepare ("
UPDATE pages
SET page_title = ?, meta_description = ?, meta_keywords = ?, $content = ?
WHERE page_uri = ?
");
$update_page->bind_param('sssss', $page_title, $meta_description, $meta_keywords, $content, $page_uri);
$update_page->execute();
這拋出我
Fatal error: Call to a member function bind_param() on a non-object
參照線4(一個最後一行以上)。
@Gaurav:這裏是完整的代碼 - 我有這個網頁上同時顯示SELECT和UPDATE語句,SELECT作品:
if (!isset($page_uri))
{
$page_uri = 'home';
}
if (isset($_POST['update']))
{
$page_title = htmlspecialchars($_POST['page_title']);
$meta_description = htmlspecialchars($_POST['meta_description']);
$meta_keywords = htmlspecialchars($_POST['meta_keywords']);
$content = htmlspecialchars($_POST['content']);
$update_page = $db->stmt_init();
$update_page->prepare ("
UPDATE pages
SET page_title = ?, meta_description = ?, meta_keywords = ?, $content = ?
WHERE page_uri = ?
");
$update_page->bind_param('sssss', $page_title, $meta_description, $meta_keywords, $content, $page_uri);
$update_page->execute();
}
$select_page = $db->stmt_init();
$select_page = $db->prepare ("
SELECT page_id, page_title, meta_description, meta_keywords, content, sidebar
FROM pages
WHERE page_uri = ?
LIMIT 1
");
$select_page->bind_param('s', $page_uri);
$select_page->execute();
$select_page->bind_result($page_id, $page_title, $meta_description, $meta_keywords, $content, $sidebar);
$select_page->fetch();
$page_title = htmlspecialchars_decode($page_title, ENT_QUOTES);
$meta_description = htmlspecialchars_decode($meta_description, ENT_QUOTES);
$meta_keywords = htmlspecialchars_decode($meta_keywords, ENT_QUOTES);
$content = htmlspecialchars_decode($content, ENT_QUOTES);
你的phpinfo()在mysqli的情況下顯示什麼? – egis 2011-02-07 13:48:59
btw,顯示您啓動$ db對象的代碼。可能是沒有選擇數據庫;) – egis 2011-02-07 13:50:08