Connection to Oracle using PHP (odbc_connect) on IIS - php

I am trying to connect to an Oracle database using the odb_connect() function in PHP. PHP is installed on IIS.
I am using the following command :
$dsn="Driver={Microsoft ODBC for Oracle};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=******)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=***)));Uid=***;Pwd=***";
$connect = odbc_connect($dsn, '****', '***') ;
Unfortunately why the script is run I get the following error :
Warning: odbc_connect(): SQL error: [Microsoft][ODBC driver for Oracle][Oracle], SQL state NA000 in SQLConnect in ..
Any ideas on why this is happening would be gratly appreciated. I have tried to look online for a solution but since i've never done this before I havn't managed to fix it.
Thanks in advance !

Related

Cannot connect to Databricks SQL Endpoint using PHP and ODBC

I am trying to connect to our Databricks SQL endpoint using PHP in a Docker container.
I setup my Docker container to download and configure the ODBC driver as specified here: https://docs.databricks.com/integrations/bi/jdbc-odbc-bi.html#install-and-configure-the-odbc-driver-for-linux
My Docker setup is at https://github.com/rlorenzo/databricks_php
However, when it try to connect using ODBC from my PHP test script I get the error:
Warning: odbc_connect(): SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect in /test_connection.php on line 14
ODBC connect failed: S1000
When I try to connect using the PDO library I get a different error message:
SQLSTATE[08S01] SQLConnect: 20009 [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist
The connection details are correct because I was able to connect to the Databricks SQL endpoint using Datagrip. I can also verify that the ODBC library is properly installed because I can query a Microsoft SQL Server.
I must have the Databricks ODBC Connector misconfigured somehow, but I am clueless. From my view everything matches the documentation.
I have tried contacting Databricks support, but they have been unhelpful so far.
The problem was that the Databricks SQL driver does not yet support ARM, which my laptop and Docker container was building for. See ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/simba/spark/lib/64/libsparkodbc_sb64.so' : file not found (0) (SQLDriverConnect)")
I updated my repo at https://github.com/rlorenzo/databricks_php with a working example and forced the container to build an x86 version.
Will update my repo if Databricks ever supports ARM.
Hope this helps someone in the future.

Connecting to SQL Server from Laravel

I'm new to SQL Server and I try to connect from PHP to my SQL Server; I've already extracted SQL Server extra into php/ext:
And after that I try to put extension into php.ini
but I always get this error:
How can I solve this? The driver never been installed then

sasql_connect(): SQLAnywhere: [-100] Database server not found

it's about more than one full day that i started sqlanywhere and i'm so interested to use it,
i worked before with sqlsrv for ms sql server and connection via php ,
but i have problem for connecting php to sqlanywhere
here is the warning message when i try to run test.php
Installation successful Using php-5.6.0_sqlanywhere.dll
Warning: sasql_connect(): SQLAnywhere: [-100] Database server not found in C:\xampp\htdocs\test.php on line 44
Connection failed
$conn = sasql_connect( "UID=DBA;PWD=sql" );
if( $conn ) {
echo "Connected successfully\n";
sasql_disconnect( $conn );
} else {
echo "Connection failed\n";
}
I'm using xampp server php 5.6 and sqlanywhere 17 developer edition.
already i downloaded the php extension and copied on ext and also added the line in php.ini (extension=php-5.6.0_sqlanywhere.dll)
demo database i ran it with cmd : dbeng17 "%SQLANYSAMP17%\demo.db".
via cmd i tried this also :
C:>dbping -d -c "uid=dba;
SQL Anywhere Server Ping U
Connected to SQL Anywhere
Ping database successful.
but when i try via php it says: Warning: sasql_connect(): SQLAnywhere: [-100] Database server not found in C:\xampp\htdocs\test.php on line 44
Connection failed
please someone tell me what is the problem ?
thank you very much.
Your PHP installation may have multiple files similar to php.ini. Make sure you are modifying the php.ini file listed in phpinfo().
- A web server such as Apache, IIS, or any web server that supports
PHP.
- PHP installed on the same computer as the web server.
- SQL Anywhere installed on the same computer as the web server.
- The client software can be used as well. SQL Anywhere PHP extension
Refrance : https://wiki.scn.sap.com/wiki/display/SQLANY/Getting+Started+with+SAP+SQL+Anywhere+and+PHP
It solved for me when I installed and used it on another system , I don't know I tried first on a system that MSSQL server was install and I couldn't run it and tried on another system that mssql server was not installed and solved :)
sorry for being late to answer and thank you very much for those who took time to help me.

Microsoft Visual FoxPro Driver connection issue

Hi i am trying to connect with visual fox pro driver using .dbc file here is the code
$dsn = "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\DataMnt\WINSIMS.DBC;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
$conn = odbc_connect($dsn, "", "");
if (!$conn)
exit("Connection Failed: " .$conn );
i am getting below error please help
Error :-( ! ) Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\wamp64\www\testfiles\odbc_test.php on line 15
even i have installed the driver and its showing in my odbc drivers list and from there i have added that driver and defined .dbc file location.
but still i am getting this error i have read out all stack overflow posts but did not get success so please help. I have added attachment of driver which i have added.
i am using wamp 64 bit on windows 64 bit system i have tested mysql connector driver and that was working fine. i just have .dbc file is there any need of username and password ? or i can fill them blank.
Thanks in advance !
Update :- Microsoft Visual FoxPro Driver is showing in windows->SysWOW64->odbcad32.exe but not showing in windows->system32->odbcad32.exe
I currently have Foxpro ODBC driver running on Windows 10. It interacts with PHP 5.6 in XAMPP 32 bit. The queries are working. I compared your connection string with mine. It looks fine except the path to sourceDB may need to be separated by double back slashes. I have user DSN instead of system DSN. Here's a screen shoot of my ODBC admin panel.
ODBC admin panel

ODBC with FreeTDS PHP Not working via HTTP

I have got FreeTDS, unixODBC and ODBC enabled on PHP. It all seems to work great. I could connect via iSQL command line.
For some reason PHP is not able to work when accessed via HTTP.
For example.
via command line if I run php index.php (where index.php connects via ODBC) it works well.
but the same code when accessed via HTTP, returns
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect
Could this be a case of some permission
Thanks in advance
Here is the connection code
$connect = odbc_connect("DSNNAME", "USERNAME", "PASSWORD") or die('e');
I have changed the credentials. But the code works fine when I run it via PHP command through SSH via Terminal. But when I run it through HTTP it does not.
Also on SSH I am NOT running it via root user. I am using ec2 AWS - and ran SSH via ec2-user (which is the default)
I feel 'apache' user does not have permission to something which I am unaware of.
You can add the DSN from the PHP source code like this
$dsn = "Driver=FreeTDS;Server=192.168.1.17;Port=1433;Database=mydb;TDS_Version=7.2;";
$Connection = odbc_connect($dsn,$user,$pass);
2021 - BACK TO THE FUTURE:
I know that this post is old, but my reply can point a desperate soul in the right direction:
You are using odbc and the command "isql" works just fine
You are using FreeTDS and the command "tsql" works just fine
Trouble is running the php scripts that have calls to odbc via FreeTDS -> keeps giving errors
Kindly read:
https://www.linuxquestions.org/questions/blog/tix-592494/freettds-libiodbc-iodbc-php-7-4-21-on-slackware-current-5-13-5-38621/

Categories