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?
– rray
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
– hyperpixel
Not the php extension. you SQL Server installed on your machine? try downloading it(driver odbc) here => http: //go.microsoft.com/fwlink/? Linkid=163712
– rray
You can see, in control panel, administrative tools, ODBC data source
– rray
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
– hyperpixel
Blz, install the odbc there.
– rray