PHP PDO could'nt not find driver - php

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.

Related

Connect to SQL Server in PHP 7.2 on Ubuntu 16.04, using Microsoft Drivers for PHP for SQL Server, works in browser but fails in command-line

I'm trying connecting a remote SQL Server database and getting its data for writting to my local Mysql database on Ubuntu. I've been using Microsoft Drivers for PHP for SQL Server (ODBC driver installed) and it works in the browsers.
But while I run it in command-line, it shows could not find driver, just like the Driver is never installed.
My environment:
Ubuntu 16.04.5
PHP 7.0.32
Apache 2.4.18
MySQL 5.7.24
The remote server is Windows Server 2012 with SQL Server 14.0.1000.
I've configured my Apache and PHP correctly followed the official tutorial (otherwise it probably could not work even in the browser), so I don't know why it doesn't work in the command-line or terminal. Please help, thanks.
You have to enable this driver in the CLI php.ini file.
To find this file, open a console and type php --ini, this will show you the path of the current php CLI ini file.

connecting php to ms sql server database

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

configure pdo_dblib - freetds already installed

I am running a Linux server that already has freetds installed, but is not configured to support dblib. Only sqlite and mysql are currently supported for PDO. MSSQL support is also enabled.
If I want to add support for dblib and enable the PDO Driver for FreeTDS/Sybase DB-lib, do I just need to run this command on the existing install:
./configure --with-pdo-dblib
If so, from which directory would I run the command?
Environment:
PHP Version 5.5.38
CENTOS 6.9
Thank you
If you have configured FreeTDS correctly, you should be able to connect like so:
$pdo = new PDO("dblib:host=mssql;dbname=$dbname", "$dbuser","$dbpwd");
If you can't, this answer gives more explicit instructions: Connect PHP to MSSQL via PDO ODBC
pdo_dblib is typically installed in most Linux distros when you install php-mssql (on CentOS and Ubuntu, for example). If the connect command isn't working, please rewrite your question to include the specific steps you have taken and the error output. Good luck!
Since writing this question, the support team at the company that is hosting this server installed the driver. I don't know exactly what steps they took to do it so I can not post a step by step answer as I would like. Closing this question.

sqlsrv drivers doesn't appear on a WAMP server phphinfo() after adding the extension entries in the php.ini file

I wanted to setup a database connection from PHP to SQL server 2012.I have a wamp server(64 bit) set up on a windows machine(64 bit) with PHP 5.5.12 and on the same machine I have SQL server 2012 installed.
Extracted sqlsrv drivers from official_link
Copied the extracted drivers php_sqlsrv_55_ts.dll, extension = php_pdo_sqlsrv_55_ts.dll to php\ext folder, and then changed the php.ini file to include the extensions
extension = php_sqlsrv_55_ts.dll; extension = php_pdo_sqlsrv_55_ts.dll;
Now I tried
<?php
phpinfo();
?>
I see the following information without any SQL server information in it.
Don't seem to have configured SQL server connection successfully. Could some one please guide me on what I am missing here.
64 bit WAMP server was not able to connect using the drivers extension = php_sqlsrv_55_ts.dll; extension = php_pdo_sqlsrv_55_ts.dll;
So, I installed a 32 bit version of the WAMP server and it works fine now.
Check the php error log (c:\wamp\logs\php_error.log).
I had the same setup (64bit WAMP/PHP 5.5.12) and same missing sqlsrv reference in phpinfo and I got this error in my log:
PHP Warning: PHP Startup: Unable to load dynamic library
'c:/wamp/bin/php/php5.5.12/ext/php_pdo_sqlsrv_55_ts.dll' - %1 is not a
valid Win32 application. in Unknown on line 0
The solution was to install the 64bit version of the sqlsrv drivers. I found the unofficial 64bit drivers through http://robsphp.blogspot.nl/2012/06/unofficial-microsoft-sql-server-driver.html
Warning: In my testing I found these 64bit PHP_PDO_SQLSRV extension 10 times slower than when using PHP_PDO_ODBC.
I am visiting this thread and i think this might help full for you and other with the same issue:
How can I install pdo_sqlsrv on my windows 2008 Server 2008 R2?
The PDO Extension is not the same as the native driver Microsoft is offering. For PDO you must enable
extension=php_pdo_mssql.dll
in your php.ini.
{Normally this file (php_pdo_mssql.dll) should be in your PHP extension-directory (C:...\php\ext). If it's not there you can download PHP from http://windows.php.net/download/ and just take the extension from a package there (take one that correspond with your PHP version of course)}.
Above is taken from PDO MSSQL Server - Driver not found
read for more details. i have the same issue foe linux and i have saved all the pages thats why i am quoting for you help.
if all above didn't work for you then:
On the php.net it is listed that
On Windows, PDO_ODBC is built into the PHP core by default. It is linked against the Windows ODBC Driver Manager so that PHP can connect to any database cataloged as a System DSN, and is the recommended driver for connecting to Microsoft SQL Server databases.
http://php.net/manual/en/ref.pdo-odbc.php
You can connect to mssql server using odbc drivers as i have never connect by my self from windows i use to do it through linux using freeTds, following pages might help you
http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/
Connect PHP to MSSQL via PDO ODBC
PHP to SQL Server without ODBC or MSSQL support

connect php pdo on sles apache to mssql database

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.

Categories