I have got a PHP (v. 5.3.17) Plugin, running on SLES11 Apache, to sent a query to a database. I have installed unixodbc (ver. 2.2.12).
I want to connect the Plugin, via PHP:PDO, to a remote MSSQL Database to run some queries.
PDO:ODBC support is enabled:
PDO support enabled
PDO drivers odbc, mysql, pgsql, sqlite, sqlite2
I tested the connection via Telnet. There I got a positive result.
telnet> open 10.22.77.18 1433
Trying 10.22.77.18...
Connected to 10.22.77.18.
Escape character is '^]'.
I can also connect via tsql to the sql-database:
#>tsql -S ms-sql -U <user> -P <passwort>
locale is "LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
Via isql I get the following error:
# isql -v ms-sql
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect
I found an instruction on Connect Linux ODBC with MSsql database.
When I execute the Skript I got neither the Message "Connection established" nor the message "No connection established". I only get the command prompt ">".
I got this prompt by connecting to a false IP, too.
I think my connection string is wrong, but why do I get no error message?
To connect to MSSQL with PDO you could use either SQL Server Driver for PHP or PDO_ODBC.
A comment in the manual for PDO_SQLSRV mentions that Microsoft has not been updating their driver for some time and that official builds only exist for 5.2, 5.3 and 5.4.
Download the SQL Server driver and extract it to your PHP extension directory. Then activate the extension in the php.ini file. You need to add the following lines to that file (You need to adapt to your downloaded files names) :
extension=php_pdo_sqlsrv_52_nts.dll
Do not forget to restart the server (It is different from restarting the services). I hope it'll help.
Related
I have an AW server with CentOS. I have installed PHP7.3 and the PHP-CLI for it. I also installed ODBC and FreeTDS modules to be able to connect to a MSSQL database.
I have written a PHP script which is connecting to this database with PDO.
When I call this script from the Browser with its URL, it works perfectly. I can connect to the database and use it.
But when I start the same script from the console using
PHP -f scriptname.php
it returns with
SQLSTATE(42000) SQL Connect: 18456 [unixODBC][FreeTDS][SQL Server]Login failed for user 'CorrectUserName'.[root#servername scriptname]
So at the moment I have no idea where to search for. Does anyone has an idea what is going wrong or what I can do to debug the problem?
I installed Microsoft SQL Server 2014 (x64)-Express and install the SQL Server Drivers for PHP 7, did changes in php.ini file also, still i am getting error while connecting php to mssql server database 'connection failed. could not find the driver'. Please help me to solve this error.
In my case, in order to access a MS SQL server database from PHP I had to do the following:
Have a PHP version installed that is compatible with microsoft SQL Server executables. Install PDO, PDO_sqlsrv driver and PDO_odbc driver.
Check the following link for instructions on how to install it.
https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver16
I'm having a very puzzling situation with PHP PDO and Oracle. I'm
running on Centos 7. My script, under Apache gets the error
"ERROR:could not find driver", however the script runs fine from the command line.
From the command line when I run a test script to list the drivers:
foreach(PDO::getAvailableDrivers() as $driver)
echo $driver, '', "\n";
it returns:
mysql oci pgsql sqlite
but when run under apache, oci is missing:
mysql pgsql sqlite
To add to this mystery, running phpinfo() shows in the section
"Additional .ini files parsed" an entry for /etc/php.d/pdo_oci.ini (for both console and apache).
Any ideas as to why the oci driver is not showing up when the script
is run under apache?
I "solved" this problem by punting on getting it to work using the Oracle installation configuration. I installed Instant Client and that got PHP to recognize the oci module both in command line and under apache (building pdo_oci with ./configure --with-pdo-oci=instantclient,/usr,11.2)
There were further issues with unrecognized TNS_ADMIN values. I worked around that by using the alternative PDO DSN spec for Oracle connections:
oci:dbname=//HOST[:PORT]/SERVICE_NAME
Thanks to anyone kind enough to have spent time on this. This experience, like many Oracle-related ones, reminds me why I use Postgres.
I'm getting error of PDO cannot find driver using PDO in environment. I'm using xamp on a Mac.
I had got to know the problem and I've installed freetds using homebrew install, and had successfully connected to the azure mssql server using below command
tsql -H 234fddfg.database.windows.net -p 1433 -U dbuser -P db123!
but I don't know what to do next.
I've tried below php code but I'm still getting the same error.
$dbh = new PDO("sqlsrv:Server=localhost;Database=mydb", "dbuser", "db123");
Driver for Microsoft SQL Server for PHP is needed to be installed for this.
Follow this link:
https://www.microsoft.com/en-in/download/details.aspx?id=20098
Perform the following steps to download and install the Microsoft Drivers for PHP for SQL Server (example below for 3.2 version):
1. Download SQLSRV32.EXE to a temporary directory
2. Run SQLSRV32.EXE
3. When prompted, enter the path to the PHP extensions directory
4. After extracting the files, read the Installation section of the SQLSRV32_Readme.htm file for next steps
Now just add the following line to your PHP.ini (this is for the non-thread safe version of PHP, which you are most likely using when you have installed PHP to use IIS FastCGI, which we recommend):
extension=php_sqlsrv.dll
And Restart server
Have you installed PDO_DBLIB, it seems that in OSX, we need to leverage PDO_DBLIB as the pdo driver connecting to MS SQL, e.g.
$pdo = new PDO("dblib:host=$dbhost;dbname=$dbname", "$dbuser","$dbpwd");
you can refer to Configure PHP environment on Mac to connect to SQL Server using PDO interface for more information.
I have been searching everywhere for solutions, but am getting more and more confused.
I am trying to connect to a SQL Server 2008 db from php using FreeTDS. The server is a MediaTemple DV 4.0 and it is running CentOS 5.7. I have a version of FreeTDS (v0.91) installed that I think I might have compiled several months back. When I run tsql -C it says my freetds.conf is in /usr/local/etc and a TDS version 5.0. I need it to be TDS version 7.0, but when I change that conf file, it does not change. And I can't find the conf file it is using. (problem 1)
I can connect to my db using tsql -H -p -U and run a query. However in my php file, I get IM002 error which I believe is a connection error to the db. I use odbc_connect for that. (problem 2, the biggest problem)
I don't even know where to start, as I have been installing, uninstalling for about the last 2 months...
I would welcome any suggestion on how to resolve the issue. As a side note, it used to work before I upgraded my DV at MediaTemple.
Thanks!
Shawn
Here is my tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: no
SQL Server 2008 actually wants TDS Version 7.3 -- not 7.0, which corresponds to SQL Server 7.
I can't provide assistance with FreeTDS debugging, but you might try a commercial driver where there's some incentive to fix problems, like my employer's offering. It's free to test for 2 weeks.
We also provide some docs on using PHP with ODBC, on the iODBC.org site.
Verify that debugging is turned on in your odbcinst.ini and that errors are sent to the defined logfile.
Try to connect and run a query using the iSQL tool and check your debug log for errors. The tool comes with the unixODBC package and uses your DSN to connect to your database.
You might also want to take a look at this page: Sometimes isql doesn't connect and tsql does