pdo页面提取

时间:2010-12-31 06:28:18

标签: php arrays pdo

我正在使用this php pdo wrapper。这是我的数据库类。

class Db
{
    private static $_pdoObject = null;
    protected static $_fetchMode = PDO::FETCH_ASSOC;
    protected static $_connectionStr = null;
    protected static $_driverOptions = array();

    private static $_username = null;
    private static $_password = null;

  public static function setConnectionInfo($schema, $username = null, $password = null, $database = 'mysql', $hostname = 'localhost')
    {
        if($database == 'mysql') {
            self::$_connectionStr = "mysql:dbname=$schema;host=$hostname";
            self::$_username      = $username;
            self::$_password      = $password;
        } else if($database == 'sqlite'){
            // For sqlite, $schema is the file path
            self::$_connectionStr = "sqlite:$schema";
        }

        // Making the connection blank
        // Will connect with provided info on next query execution
        self::$_pdoObject = null;
    }
    public static function getResult($sql, $params = array())
    {
        $statement = self::_query($sql, $params);
        return $statement->fetchAll(self::$_fetchMode);

    }

    private static function _query($sql, $params = array())
    {
        if(self::$_pdoObject == null) {
            self::_connect();
        }

        $statement = self::$_pdoObject->prepare($sql, self::$_driverOptions);
    $arrayjson1=array(
            'success' => false,
            'message'=>'database error '
        );
     $msg= formjson(array(),array(),$arrayjson1);
        if (! $statement) {
            $errorInfo = self::$_pdoObject->errorInfo();
        //~ print_r($errorInfo);
            //~ echo $msg;exit; 
            throw new PDOException("Database error [{$errorInfo[0]}]: {$errorInfo[2]}, driver error code is $errorInfo[1]");
        }

        $paramsConverted = (is_array($params) ? ($params) : (array ($params )));

        if ((! $statement->execute($paramsConverted)) || ($statement->errorCode() != '00000')) {
            $errorInfo = $statement->errorInfo();
                //~ print_r($errorInfo);
            throw new PDOException("Database error [{$errorInfo[0]}]: {$errorInfo[2]}, driver error code is $errorInfo[1]");
        //~ echo $msg;exit;
        }

        return $statement;
    }
}

我正在调用此查询以获取所有用户

     $sql="select  userid,concat_ws(' ',firstname,lastname) as name $fields 
        from users where 1=1   $condition order by updatedon $limit";
    $row=Db::getResult($sql,$query);

我希望通过

  

输入

传递

  
      
  1. 否。每页记录数   2.页面编号
  2.   

这样它

  

输出

来应该是每页记录的页面记录。

我如何在pdo中实现这一目标。

请帮忙。谢谢

1 个答案:

答案 0 :(得分:0)

阅读以下文章。这将有助于您了解您感兴趣的标准。

paging