When I run php from the command line this works perfectly and my query executes without issue. IF I access via web though it times out.
function query_sql2($query,$ar,$results =1)
{
global $hostname,$username,$password;
$mssqldriver = '{ODBC Driver 17 for SQL Server}';
//$mssqldriver = '{ODBC Driver 13 for SQL Server}';
$dbname='unclaimed';
$odbc="odbc:Driver=$mssqldriver;Server=$hostname;Database=$dbname;";
$result = array();
try {
$dbDB = new PDO($odbc, $username, $password);
$dbDB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if($dbDB)
{
//echo "Connected!";
$sql = "set ANSI_WARNINGS on
set ANSI_PADDING on
set ANSI_NULLS on
set ARITHABORT on
set QUOTED_IDENTIFIER on
set NOCOUNT on
set ANSI_NULL_DFLT_ON on
set CONCAT_NULL_YIELDS_NULL on
".$query;
$query = $dbDB->prepare($sql);
$query->execute($ar);
if($results ==1)
{
$result = $query -> fetchAll(PDO::FETCH_ASSOC);
}
}
}
catch(Exception $e) {
echo 'Exception -> ';
var_dump($e->getMessage());
}
//$sth = null;
$dbDB = null;
return $result;
}
print_r(query_sql2("exec signedDocument.dbo.sp_signeddocument_modify ;",[],1));
But if I run via my apache I get this error SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
I chomod to 777 in etc and in opt/Microsoft which is a no no, but nothing is working. Here is my output from odbcinst -j
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
And last here is my odbcinst.ini (None of those other files exist listed above)
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1
UsageCount=1
Don't know what else to try