【发布时间】:2015-01-23 02:44:45
【问题描述】:
我正在尝试制作一个可以在所有网站上使用的基本计数器。
我有一个查询我的 Go Daddy MySQL 服务器和我的 MAMP MySQL 服务器的准备好的语句,并且该语句不会“准备”。这里是:
function hit_counter($url){
if($mysqli = new mysqli('localhost', 'root', '', 'DB')){
$crack = "SELECT hc-id, hc-url, hc-unique_hits, hc-total_hits, hc-last_viewed FROM hit_counter WHERE hc-url =?";
if($stmt = $mysqli->prepare(crack)){
$stmt->bind_param('s', $url);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $url, $unique_hits, $total_hits, $last_viewed);
$stmt->fetch();
echo "the statement was prepared successfully";
$total_hits = $total_hits+1;
$last_viewed = date('l jS \of F Y h:i:s A');
echo $unique_hits;
if($unique === true){
$unique_hits = $unique_hits+1;
}
$update = 'UPDATE hit_counter set hc-unique_hits=? hc-total_hits=? hc-last_viewed=? WHERE hc-url=?';
if($stmt= $mysqli->prepare($update)){
$stmt->bind_param('iiss', $unique_hits, $total_hits, $last_viewed, $url);
$stmt->execute();
}else{echo "the update statement wasn't prepared.";}
}else{echo "The statement wasn't prepared.";}
}else{echo "the SQL connection wasn't made";}
}
我知道它正在连接到数据库,但是每当我运行脚本时,它都会回显 if($stmt = $mysqli->prepare(crack)){ "The Statement wasn't prepared" 的 else 语句。
【问题讨论】:
-
SET 语句之间需要逗号,
set hc-unique_hits=?, hc-total_hits=?,... -
存在一个特定的已知问题,因此这并不是真正的代码审查。但是,将来如果您确实需要代码审查,可以使用 separate Stack Exchange site for that
-
启用错误报告...(对于 PDO 和 PHP)
-
您的“Go Daddy SQL Server” - 您是指 Microsoft SQL Server 还是 MySQL?
-
(我已经删除了代码审查的请求 - 我认为问题本身就是主题,因为它与特定问题有关。最好不要在这里请求代码审查,因为它听起来也是一般,并且可以解决一个本来很好的问题)。