Jump to content

Sql Server 2019 odbc connection help


twdavis
Go to solution Solved by twdavis,

Recommended Posts

I can connect to the sql server 2019  from my linux machine with tsql but not with isql or with PHP odbc_connect. I can connect to older SQL Servers. I have tried a lot of different thing including FreeTDS. isql error is [ISQL]ERROR: Could not SQLConnect

my odbcinst.ini

[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

[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

[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.5.1
UsageCount=1

My odbc.ini

[KF-M1]
Driver=FreeTDS
Trace=Yes
Servername=KF-M1
Database=M1_KF

Link to comment
Share on other sites

 


PHP Fatal error:  Uncaught Error: Call to undefined function odbc_connect() in /var/www/html/V9/connection.php:19
Stack trace:
#0 {main}
  thrown in /var/www/html/V9/connection.phpI get this error from PHP Connection 

my php Connect

<?php


ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//echo "Connection page";

$name = 'kf-m1';
$user = 'user';
$password = 'password';

$hostname='ipaddress';
$dbname='M1_KF';
$username='user';
$password='password';

$connect =odbc_connect($name,$user,$password);
if(!$connect) {
    exit("Connection Failed: " . $connect);
};

?>

 

Edited by twdavis
Link to comment
Share on other sites

Run this code pointing to the new SQL server I get and error. But pointing to the old SQL server it works fine. and line 24 is the odbc_connect.

Error:

Warning: odbc_exec(): SQL error: [FreeTDS]

The cursor was not declared., SQL state 37000 in SQLExecDirect in /var/www/html/V9/bs_kf_orders_shipped_sum1.php on line 24
Error in SQL
 
   <?php include 'connection.php';?>
    
</head>
<body>
<?php


$gr_total = 0;
$total=0;
$sql="  select
  impPartClassID,sum(omlExtendedPriceBase) as Total1 ,sum(omlQuantityShipped) as qty
 
  from m1_kf.dbo.SalesOrders
left outer join m1_kf.dbo.SalesOrderLines on omlSalesOrderID=ompSalesOrderID
Left Outer join m1_kf.dbo.Parts on impPartID=omlpartid
LEFT JOIN m1_KF.dbo.Organizations og ON cmoOrganizationID = ompShipOrganizationID
 
 where ompcloseddate= '12-05-2023' and omlQuantityShipped !=0


group by impPartClassID";
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
 while ($row = odbc_fetch_array($result))
{
echo "<tr><td>" . $row['impPartClassID'] ."</td>";
echo "<td>" . number_format($row['Total1'],2) ."  "."</td>";
echo "<td>" ." Qty ".number_format($row['qty'],0)."<br></td></tr>"; 
    
$total = $total + $row['Total1'];    
  
 }


odbc_close($connect);
$gr_total=number_format($total,2);
echo "Total"."  ". $gr_total 
?>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.