在我的 Joomla 2.5.14 中,我试图将当前 page_id、user_id 和日期插入到 mySQL 表(称为 xmb9d_hist)中。
这是我正在使用的代码:
<?php
/* Define $jinput */
$jinput = JFactory::getApplication()->input;
/* Get the current page id */
$page= $jinput->get('id');
/* Get the current user id */
$user =JFactory::getUser();
$usr_id = $user->get('id');
/* Get the current date */
$date =JFactory::getDate();
/* Open a connection */
$link=mysqli_connect('localhost','peter','abc123');
if(!$link){
echo "Não há ligação!";
exit();
};
/* Insert current user id, page id and date in to table xmb9d_hist */
mysqli_query($link, "INSERT INTO `portalge_formacao`.`xmb9d_hist` (`user_id`, `page_id`, `date`) VALUES ($usr_id, $page, $date)");
/* Close connection */
mysqli_close($link);
?>
代码的第一部分工作正常(检索 3 个变量的值。但是,数据没有插入数据库中,也没有产生错误。
在 MySQL 表中,user_id 和 page_id 定义为 INT(11),date 定义为 date。
在此先感谢您的帮助。