Rafbor ha scritto: ↑lunedì 8 aprile 2024, 18:31
Salve, non so se hai letto la
guida di Microsoft, dice che "Port" non è una parola chiave valida nel file odbc.ini, guarda l'esempio fornito.
ho seguito le tue indicazioni, ma continuo ad avere problemi.
Andiamo per punti
Questo non l'ho mai configurato
file odbcinst.ini
Codice: Seleziona tutto
cat /etc/odbcinst.ini
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
UsageCount=1
questo l'ho configurato seguendo la guida di MS
Codice: Seleziona tutto
# [DSN name]
[NEWSQL2019]
driver = ODBC Driver 18 for SQL ServerServer
# Server = [protocol:]server[,port]
server = tcp:192.168.1.170,1433
Encrypt = yes
Quando testo il mio script in php non funziona
Codice: Seleziona tutto
<?php
/* Specify the server and connection string attributes. */
$serverName = "tcp:192.168.1.170,1433"; /*"NEWSQL2019";*/
/* Get UID and PWD from application-specific files. */
$uid = "sa";
$pwd = "Password@1";
$connectionInfo = array( "UID" => $uid, "PWD" => $pwd, "Database" => "OS1_NES");
/*$serverName = "tcp:myserver.database.windows.net,1433";
$connectionOptions = array("Database"=>"AdventureWorks","Uid"=>"MyUser", "PWD"=>"MyPassword");*/
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn == false)
echo "Errore su Sqlsrv_connect 1!!</br></br>";
print_r (sqlsrv_errors());
die(FormatErrors(sqlsrv_errors()));
return $conn;
/* Connect using SQL Server Authentication. */
$conn = odbc_connect("DataDirectMSSQL", $uid, $pwd);
//sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
} else
{ echo "connessione al DB riuscita!";}
/* Query SQL Server for the login of the user accessing the
database. */
$tsql = "SELECT * FROM [OS1_NES].[dbo].[OCS_Utenti]";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
/* Retrieve and display the results of the query. */
$row = sqlsrv_fetch_array($stmt);
echo "User login: ".$row[0]."</br>";
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
questo è l'errore
Codice: Seleziona tutto
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate] [message] => [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate] ) [1] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection. For solutions related to encryption errors, see https://go.microsoft.com/fwlink/?linkid=2226722 [message] => [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection. For solutions related to encryption errors, see https://go.microsoft.com/fwlink/?linkid=2226722 ) )