Error connecting php 5.5 to SQL Server

Asked

Viewed 580 times

4

I can’t make a simple Conn work between sql server and php!!

I already downloaded and left in the ext folder the drivers according to my version of php

I already referenced them in php.ini restarted

And when I’m going to test the subject of this error below the code, someone knows how to solve, unbelievable that microsoft can’t do anything right a simple connection to their bank huge torment.

  $servidor = "MEU\SQLSERVER";
  $basedatos = "novo";#
  $usuario = "novo";#
  $pass = "senha";

  $info = array('Database' => $basedatos);
  $conexion = sqlsrv_connect($servidor, $info);


  if (!$conexion) {

    die(print_r(sqlsrv_errors(), true));

  }

echo 'Conectado';

error:

  Array([0] => Array([0] => IMSSP[SQLSTATE] => IMSSP[1] => -49[code] => -49[2] => This extension requires the Microsoft ODBC Driver 11
        for SQL Server.Access the following URL to download the ODBC Driver 11
        for SQL Server
        for x86: http: //go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Nome da fonte de dados não encontrado e nenhum driver padrão especificado [message] => [Microsoft][ODBC Driver Manager] Nome da fonte de dados não encontrado e nenhum driver padrão especificado ) )

I tried another code that Ocaweb is giving another error

$tabela = "nometabela";    #Nome da tabela
$campo1 = "campo1tabela";  #Nome do campo da tabela
$campo2 = "campo2tabela";  #Nome de outro campo da tabela

$conninfo = array("Database" => $db, "UID" => $user, "PWD" => $password);
$conn = sqlsrv_connect($dbhost, $conninfo);

$instrucaoSQL = "SELECT $campo1, $campo2 FROM $tabela ORDER BY $campo1";

$params = array();
$options =array("Scrollable" => SQLSRV_CURSOR_KEYSET);

#ESSE DEU ERRO AQUI
$consulta = sqlsrv_query($conn, $instrucaoSQL, $params, $options);
$numRegistros = sqlsrv_num_rows($consulta);

echo "Esta tabela contém $numRegistros registros!\n<hr>\n";

if ($numRegistros!=0) {
    while ($cadaLinha = sqlsrv_fetch_array($consulta, SQLSRV_FETCH_ASSOC)) {
        echo "$cadaLinha[$campo1] - $cadaLinha[$campo2]\n<br>\n";
    }
}
  • The ODBC you have installed on the machine?

  • how do I see? I am using win 8 I downloaded the dll from ms and left it in ext folder and set them in php.ini I am using xampp

  • Not the php extension. you SQL Server installed on your machine? try downloading it(driver odbc) here => http: //go.microsoft.com/fwlink/? Linkid=163712

  • You can see, in control panel, administrative tools, ODBC data source

  • I actually want to access a remote server. my odbc looks like this : user dns tab: has excel files and ms db accesses and in driver tab has sqlserver + sql server Native client 10 and 11

  • Blz, install the odbc there.

Show 1 more comment

1 answer

4

  • 1

    swirled was the lack of driver thanks guy I’m new in the company saved my neck ;)

  • 1

    Great, if my answer helped you mark it as right. ;)

Browser other questions tagged

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