Doctrine2 + pdo_sqlsrv createQueryBuilder Order By with varchar field does not work

Asked

Viewed 109 times

0

I’m creating a method that takes values for createQueryBuilder() from parameters.

I tested in my local database with pdo_mysql driver and it worked perfectly, sorting both by a field of type int (id) and by a field of type varchar (title).

However, after testing in another database on an external server with pdo_sqlsrv driver (and also sqlsrv driver) it works when "order by" is by a field of type int (id), but when the sort is by a field of type varchar (title) it gives timeout on the connection.

Follow the source prints of the return by mysql database and Sqlserver database:

public function getBy($fields, $orderBy, $where = null, $params = null)
{
    if (empty($where))
        $where = '1 = 1';

    $query = $this->getEntityManager()->createQueryBuilder()
        ->select($fields)
        ->from($this->entity, $this->alias)
        ->where($where)
        ->add('orderBy', $orderBy)
        ->setFirstResult(URIHelper::$arrayParams['offset'])
        ->setMaxResults(URIHelper::$arrayParams['limit'])
        ->getQuery();

    if (!empty($params))
        $query->setParameters($params);

    print_r($query->getSQL());
    //print_r($query->getParameters());
    //print_r($query->getArrayResult());
    //die();
    return $query->getArrayResult();
}

OK return when using Mysql database sort title(varchar):

Retorno OK quando uso banco MySQL ordenação titulo(varchar):

OK return when using Sqlserver database id(int sorting):

Retorno OK quando uso banco SqlServer ordenação id(int):

Return ERROR when using Sqlserver bank sorting title(varchar): Retorno OK quando uso banco SqlServer ordenação titulo(varchar):

  • SQL Server 2012? What is the driver version pdo_sqlsrv that you’re using?

  • SQL Server 2012, yes. Installation and configuration by IIS 8, with PHP 5.4 and 5.6 and Driver 3.2 compatible with PHP 5.4 and 5.6. But it shouldn’t be that, otherwise the query would not work by sorting by id either. It just doesn’t work when sorting by title or ad (both scan).

  • Try setting up IIS for a longer timeout time. In php.ini you increase max_execution_time, max_input_time, default_socket_timeout, sqlsrv.connect_timeout and sqlsrv.timeout. Maybe that’s it, since the code returns the Fatal Error down there talking at maximum execution time exceeded and at the top appears the error 08S01 of ODBC 11. Try to optimize your query also.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.