PHP无法从数据库中获取更大的数据

 收藏

Function getUsers_Test() can retrieve data with the limit of 10 rows only while my getUsers_Orig() cannot retrieve any records **my record in the database is almost 50 rows*. No error, no warning. (PHP version 5.5.12)

function getUsers_Test(){
    $sql = "SELECT TOP 10 a.user_name, a.user_level, a.user_status, b.* FROM user_access a, user_details b WHERE a.emp_code = b.emp_code ORDER BY a.id DESC";
    try{
        $data = array();
        $db = null;
        $db = connectDB();
        $stmt = $db->prepare($sql);
        $stmt->execute();
        $data = $stmt->fetchAll();

    }catch(PDOException $e){
        $data['message'] = "Error: " . $e;
    }
    echo json_encode($data);
}

    function getUsers_Orig(){
    $sql = "SELECT a.user_name, a.user_level, a.user_status, b.* FROM user_access a, user_details b WHERE a.emp_code = b.emp_code ORDER BY a.id DESC";
    try{
        $data = array();
        $db = null;
        $db = connectDB();
        $stmt = $db->prepare($sql);
        $stmt->execute();
        $data = $stmt->fetchAll();

    }catch(PDOException $e){
        $data['message'] = "Error: " . $e;
    }
    echo json_encode($data);
}

    function connectDB() {
    $dbuser = "myusername";
    $dbpass = "mypassword";
    $dbh = new PDO('odbc:databaseName', $dbuser, $dbpass);
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $dbh;
}
回复
  • 您可以尝试捕获一般异常而不是PDOException

    try
    {
      // ...
    } catch (\Exception $e) {
      // ...
    }