On my development environment I have static function within a Class wherein I can retrieve a list of a table's data and print to screen. It works great. Here is my code:
public static function getList( $numRows=1000000, $order="name ASC" ) {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM posttypes ORDER BY " . mysql_real_escape_string($order) . " LIMIT :numRows";
$stmt = $conn->prepare( $sql );
$stmt->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
$stmt->execute();
$list = array();
while ( $row = $stmt->fetch() ) {
$postType = new PostType( $row );
$list[] = $postType;
}
//Now get total number of posts that match criteria
$sql = "SELECT FOUND_ROWS() AS totalRows";
$totalRows = $conn->query( $sql )->fetch();
$conn = null;
return ( array( "results" => $list, "totalRows" => $totalRows[0] ) );
}
However, on my production environment I cannot retrieve any records. But if I run that exact query inside phpMyAdmin I get the exact record I want.
Not sure what is going on? This is my first time setting up to a production environment. I am using Blue Host.
UPDATE: Okay, I fixed it by removing mysql_real_escape_string, however I believe it is safer to escape the string, but this must be returning false and failing the SQL Statement. Thanks everyone for help.