I have this code that works on my localhost connecting to my Godaddy database, but when I put it up on the Godaddy server, it does not work. What needs to be changed to make it work? I know that the connection to the database works because I have another PHP file that retrieves items with no problem.
It connects to the DB, then tries to execute the following code:
try {
$dbh = new PDO($dns, $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$pdo = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
$items = [];
$start = isset($_GET['start']) ? (int)$_GET['start'] -1 : 0;
$count = isset($_GET['count']) ? (int)$_GET['count'] : 1;
$item = $dbh->query("SELECT SQL_CALC_FOUND_ROWS * FROM portfolio_items LIMIT $start, $count");
$itemsTotal = $dbh->query("SELECT FOUND_ROWS() AS count")->fetch(PDO::FETCH_ASSOC)['count'];
if($itemsCount = $item->rowCount()) {
$items = $item->fetchAll(PDO::FETCH_OBJ);
}
echo json_encode(array(
'items' => $items,
'last' => ($start + $count) >= $itemsTotal ? true : false,
'start' => $start,
'count' => $count
));
}
catch (PDOException $e) {
error_reporting(E_ALL);
}
?>