PHP - SQL不返回行但在本地服务器上工作
问题描述:
Im trying to get a row, But it does not return anything on my site, But it works perfectly on local host.
public function GetVote($rel)
{
include 'config.php';
$stmt = $dbh->prepare("SELECT updown FROM user_votes WHERE UID = :id AND rel = :rel");
$stmt->bindParam(":id", $this->id);
$stmt->bindParam(":rel", $rel);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row['updown'];
}
Running SQL on phpmyadmin, Site:
Running SQL on phpmyadmin, Local:
- I dont know why its saying there is no unique colum, VID is unique and auto-increment.
Table structure:
答
VID
is unique, but your are only SELECT
ing the updown
field. Therefore, phpMyAdmin can't let you edit the data and it produces that warning.
Also, try following query:
SELECT *
FROM `user_votes`
WHERE `UID`='76561197996836099'
AND `rel`='5'
LIMIT 0,30
I've noticed the UID
and ref
fields are varchar, but you're sending an integer (way to big, btw)...
答
just try this and tell..any output or not??
public function GetVote($rel)
{
include 'config.php';
$stmt = $dbh->prepare("SELECT * FROM user_votes WHERE rel = :rel");
$stmt->bindParam(":rel", $rel);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row['updown'];
}