How to connect to SQL Anywhere database from linux? - php

I want to access to a SQL Anywhere database which is on another server.
I can do it easily from Windows, but I need to do it from Debian now.
All of this in php.
Windows side :
I have installed SQL anywhere driver from https://archive.sap.com/documents/docs/DOC-35857, and connect with odbc:Driver={SQL Anywhere 16};Server=serveur-02;Port=2638;Database=excalib;Uid=username;Pwd=pwd;
Ok, it works.
Debian side :
I am on Debian 9 with php 7.0.
UnixODBC is already installed and works with some others connections.
FreeTDS is installed too.
So I have make a link in odbcinst.ini :
[SQLAnywhere16]
Description = SQLAnywhere driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
And in odbc.ini :
[Excalibur]
Description = Excalibur
Driver = SQLAnywhere16
Server = [ip]
Port = 2638
Name = excalib
User = user
Password = password
With command
isql -v Excalibur
I got
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[08004][unixODBC][FreeTDS][SQL Server]Erreur SQL Anywhere -83 : La base de
donn▒es sp▒cifi▒e est introuvable
[ISQL]ERROR: Could not SQLConnect
As I understand, it reaches server, but don't find my database. Ok, it's encouraging. Maybe a typo mistake, but I can't find documentation which can tell me, maybe someone has a hint ?
Next step is to do it with php.
odbc:Driver={SQLAnywhere16};Server=[ip];Port=2638;Database=excalib;Uid=user;Pwd=pwd
And... it does nothing. I got nothing from my server (ERR_EMPTY_RESPONSE)
There's nothing in apache's log.
If I do a typo mistake on purpose on the driver path, it sends a correct error
Fatal error: Uncaught PDOException: SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib '/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so1' : file not found in /var/www/html/test.php:24 Stack trace: #0 /var/www/html/test.php(24): PDO->__construct('odbc:Driver={SQ...') #1 {main} thrown in /var/www/html/test.php on line 24
And... I'm lost. Someone can help me ? Or maybe has another solution to connect to SQLAnywhere database ?
Thank you.
Edit [thank to Nitrex] :
When I try to connect via php, tcpdump doesn't capture anything, so I think the problem come from Debian side.

Related

PHP PDOException: could not find driver but driver is installed?

I'm running PHP 7.1 on an IIS 10.0 server and trying to connect to a MSSQL database.
Trying to instantiate a connection like this:
$dbh = new PDO("sqlsrv:Server=#server#;Database=#dbname#", "#username#", "#passwd#");
Gives me this error:
Fatal error: Uncaught PDOException: could not find driver in C:\inetpub\wwwroot\projects\test.php:6 Stack trace: #0 C:\inetpub\wwwroot\projects\test.php(6): PDO->__construct('sqlsrv:Server=...', '#username', '#pwd...') #1 {main} thrown in C:\inetpub\wwwroot\projects\test.php on line 6
However, sqlsrv is activated in my php.ini:
extension=php_sqlsrv.dll
extension=php_pdo_sqlsrv.dll
It's uncommented, and it's the right php.ini (already checked with phpinfo()). Restarting the server also didn't do anything.
I really don't understand why this is happening when the driver is obviously installed :/
What makes it extra weird is that I have another application running on the same server that also connects to a MSSQL database and it works with no problems, it had an automatic installer though so I didn't have to configure anything myself. It also connects to a local db and right now I'm trying to connect to a remote one if that makes a difference.

How to setup a mongodb with php XAMPP?

I am a beginner to mongoDB, I want to learn mongoDB. So I read few tutorials and tried to configure mongoDB in my local machine, for that I have downloaded mondoDB's php_mongo.dll file and placed that on my local machine into the path "php/ext/php_mongo.dll" and after that I added this code "extension = php_mongo.dll" to php.ini file, after that I am trying run my XAMPP server but immediately it is showing the below error :
C:xampp\php\ext\php_mongo.dll is either not designed to run on Windows
or it contains an error. Try installing the program again using the
original installation media or contact your system administrator or
the software vendor for support.
after that somehow Apache server has been started And when I try to run the application on browser by URL http://localhost/mongoapp/index.php then it is throwing the following error:
Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\xampp\htdocs\mongoapp\index.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\mongoapp\index.php on line 3
File: index.php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->mydb;
echo "Database mydb selected";
My php version is "PHP Version 7.0.8". hope someone helps, Thanks in advance.
Check your phpinfo if mongodb is loaded.
Download mongodb from "https://www.mongodb.com/download-center?jmp=nav#community" and install.
Check your architecture in phpinfo match with mongodb.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

[unixODBC][Driver Manager]Data source name not found, and no default driver specified

I'm updating a application to stop using 'mssql_connect' to use PDO with ODBC for PHP 7.
Locally, I'm using XAMPP on Windows 8 and my application works fine. However, when I upload it to the Ubuntu server (Locaweb hosting, in Brazil) it returns the following error:
PDOException: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified in /public_html/user/log-connections/connection.php:28 Stack trace: #0 /public_html/user/log-connections/connection.php(28): PDO->__construct('odbc:Driver={SQ...') #1 /public_html/user/log-connections/login.php(2): require_once('/public_html/user...') #2 {main}
The line causing the error (connection.php:28) is this one:
$pdo = new PDO("odbc:Driver={SQL Server}; Server={$servername}; Database={$dbname};", $username, $password);
I already tried using other driver names, such as "SQL Server Native Client", "FreeTDS", etc. But all returns the same error. Another thing is that the SQL Server isn't on the same server.
The solutions that I found on my research was telling me change the odbc.ini file and other files. But, I don't have access to those file on the server. Besides, on my local, I didn't change none of those files, just extended the modules to activate PDO and ODBC on the PHP.
Also, I already checked the phpInfo and the PDO and ODBC are enabled with "PDO Driver for ODBC (unixODBC)".
Anyone have experienced this kind of problem?

Can connect locally but not remotely

I am facing an issue in connecting my php client to my mongodb server.
Basically, I installed MongoDB on my server (hosted in the US), I can connect to it locally when I am connected to it via ssh.
But I can't connect to this server on remote from my php client, here is the error that I get :
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: xxx.xxx.xxx.xxx:27017: Connection refused' in /var/www/pages/news.php:9 Stack trace: #0 /var/www/pages/news.php(9): MongoClient->__construct('mongodb://xxx.xxx...') #1 {main} thrown in /var/www/pages/news.php on line 9
I am using this in order to create a connection from my php client :
$m = new MongoClient("mongodb://xxx.xxx.xxx.xxx");
My remote server is Ubuntu 12.04 and I already added the INPUT and OUTPUT rules in iptables to allow traffic for the port 27017.
I don't really know where the issue comes from ? (I did not add any authentication credentials to my mongodb instance, its a new one for testing purposes).
If anyone had the same issue and found a solution, it could be helpful, thank you !
Ok guys, found the issue :
I typed this command in order to display the listening services and their corresponding ports:
netstat -anltp | grep "LISTEN"
I saw that SSH was listening with the IP : 0.0.0.0
But mongod was listening on the local interface 127.0.0.1
I just had to update the mongodb configuration file here :
/etc/mongodb.conf and set the parameter "bind_ip" to : 0.0.0.0
and uncommented the "port" field to use the default one : 27017.
As a result, now I can connect from my client to my mongod instance on my server.
Hope this helps !

PHP Connection to MS SQLServer 2008 from Linux via PDO

I need to connect to a MS SQLServer 2008 service from PHP on Ubuntu, and I would like to do so using PDO. I believe I have installed all the prerequisite libraries, and I am indeed able to connect using tsql on the command line and using mssql_connect() in code. I can't figure out what the proper DSN is, or if there are any additional PDO-specific configuration steps I am missing.
I am using the following DSN (where $db* variables are populated with their appropriate values):
odbc:Driver=FreeTDS;SERVER=$dbServer;DATABASE=$dbSchema;UID=$dbUser;PWD=$dbPasswd"
My error message is:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /home/timothy/test.php:4
Stack trace:
#0 /home/timothy/test.php(4): PDO->__construct('odbc:Driver=Fre...')
#1 {main}
thrown in /home/timothy/test.php on line 4
What additional configuration steps have I over looked?
Thanks in advance.
You shouldn't need any additional configuration if you can connect with tsql and the mssql extension. You probably just don't have the correct dsn. This documentation should help. Try new PDO("dblib:host=xx.xx.xx.xx;dbname=mydatabase", "username", "password");

Categories