Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro conectar banco sql server

Estou tentando conectar em banco sql server, já coloquei no php.ini as extensões. Quando rodo no terminal

php artisan migrate

retorna "could not find driver", o que está faltando?

extension=php_pdo_sqlsrv_71_ts_x86
extension=php_sqlsrv_71_ts_x86

No meu arquivo .env

DB_CONNECTION=sqlsrv
DB_HOST=xxx
DB_PORT=1433
DB_DATABASE=database
DB_USERNAME=username
DB_PASSWORD=password

Retorno no terminal

PHP Warning:  PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_71_ts_x86' (tried: ext\php_pdo_sqlsrv_71_ts_x86 (%1 nÒo Ú um aplicativo Win32 vßlido.), ext\php_php_pdo_sqlsrv_71_ts_x86.dll (NÒo foi possÝvel encontrar o m¾dulo especificado.)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'php_sqlsrv_71_ts_x86' (tried: ext\php_sqlsrv_71_ts_x86 (%1 nÒo Ú um aplicativo Win32 vßlido.), ext\php_php_sqlsrv_71_ts_x86.dll (NÒo foi possÝvel encontrar o m¾dulo especificado.)) in Unknown on line 0

   Illuminate\Database\QueryException  : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)

  at C:\AppServ\www\extranetPacto\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("could not find driver")
      C:\AppServ\www\extranetPacto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:31

  2   PDOException::("could not find driver")
      C:\AppServ\www\extranetPacto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:27

  Please use the argument -v to see more details.

   Whoops\Exception\ErrorException  : PHP Startup: Unable to load dynamic library 'php_sqlsrv_71_ts_x86' (tried: ext\php_sqlsrv_71_ts_x86 (%1 no  um aplicativo Win32 vlido.), ext\php_php_sqlsrv_71_ts_x86.dll (No foi possvel encontrar o mdulo especificado.))

  at Unknown:0
    1|
3 respostas
solução!

Olá Suelen!

Poderia me mandar por aqui o código do seu arquivo PDOConnection.php por favor?

<?php

namespace Doctrine\DBAL\Driver;

use Doctrine\DBAL\ParameterType;
use PDO;
use function count;
use function func_get_args;

/**
 * PDO implementation of the Connection interface.
 * Used by all PDO-based drivers.
 */
class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
{
    /**
     * @param string       $dsn
     * @param string|null  $user
     * @param string|null  $password
     * @param mixed[]|null $options
     *
     * @throws PDOException In case of an error.
     */
    public function __construct($dsn, $user = null, $password = null, ?array $options = null)
    {
        try {
            parent::__construct($dsn, $user, $password, $options);
            $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]);
            $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (\PDOException $exception) {
            throw new PDOException($exception);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function exec($statement)
    {
        try {
            return parent::exec($statement);
        } catch (\PDOException $exception) {
            throw new PDOException($exception);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function getServerVersion()
    {
        return PDO::getAttribute(PDO::ATTR_SERVER_VERSION);
    }

    /**
     * {@inheritdoc}
     */
    public function prepare($prepareString, $driverOptions = [])
    {
        try {
            return parent::prepare($prepareString, $driverOptions);
        } catch (\PDOException $exception) {
            throw new PDOException($exception);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function query()
    {
        $args      = func_get_args();
        $argsCount = count($args);

        try {
            if ($argsCount === 4) {
                return parent::query($args[0], $args[1], $args[2], $args[3]);
            }

            if ($argsCount === 3) {
                return parent::query($args[0], $args[1], $args[2]);
            }

            if ($argsCount === 2) {
                return parent::query($args[0], $args[1]);
            }

            return parent::query($args[0]);
        } catch (\PDOException $exception) {
            throw new PDOException($exception);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function quote($input, $type = ParameterType::STRING)
    {
        return parent::quote($input, $type);
    }

    /**
     * {@inheritdoc}
     */
    public function lastInsertId($name = null)
    {
        try {
            return parent::lastInsertId($name);
        } catch (\PDOException $exception) {
            throw new PDOException($exception);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function requiresQueryForServerVersion()
    {
        return false;
    }
}

Descobri que estava usando o driver sql server pra versão errada do php, estou usando a versão 7.3.5 do php e estava colocando o driver da versão 7.1, alterei e depois descobri que no arquivo .env na conexão com o sql server não precisa colocar a porta, feito isso consegui conectar com o sql server.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software