when running this query in phpMyAdmin, I get the correct values, but when using the same line in a PHP script, It always gives x=0 y=0.
All other values are correct only x and y for some reason return 0.
EDITED not getting the right values
code:
$sql = "select a.image_id as id,
i.image_url as url,
i.image_x as x,
i.image_y as y
from album a
join images i
where a.album_id = 1
and
i.image_id = a.image_id";
echo getFunc($sql);
function getFunc($sql) {
try {
$db = getConnection();
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$db = null;
return json_encode($result);
} catch(PDOException $e) {
echo $e->getMessage();
}
};
function getConnection() {
$dbhost="127.0.0.1";
$dbuser="root";
$dbpass="";
$dbname="efrattest";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->exec("set names utf8");
return $dbh;
}
mySQL table:
image_id int(11)
image_url varchar(250)
image_x int(9)
image_y int(9)
;after the first line... (Where you do your$sql = [...])