Connect MS SQL with PHP 5.6 on Centos7 - sql-server

Im trying to connect a project to an MS SQL but I can't. I read a lot but no one answer helps me.
Now I´m trying with ADOdb with mssql driver but the connection answer is:
Missing extension for mssql
So I suppose I have to install it but I can't find how can do it for PHP 5.6 on Centos. Anyone?
Or maybe other way to reach the DB?
I already tried yum install php56-php-mssql, php56w-mssql but all of them are miss. And yum install php-mssql answer that package
is already installed
UPDATE
1) tsql test works
2) php-mssql connection in php also works WHEN RUN FROM THE SHELL
3) running PHP through apache does NOT work.
I found the mssql.so and added the path to my php.ini file, then restarted apache but when I load a page with phpinfo(), mssql.so doesn't show.
What is missing?

PROBLEM SOLVED
1) Download PHP5.6 source files.
2) go to php/ext/mssql
3) do phpize but with php used by Plesk located on /opt/plesk/php/5.6/bin/phpize
4) configure, make
5) copy generated *.so to extensions folder on /opt/plesk/php/5.6/lib64/php/modules
6) create /opt/plesk/php/5.6/etc/php.d/mssql.ini file with tho following text:
; Enable mssql extension module
extension=mssql.so
7) restart apache

Related

Airflow 2.0 SQL Server connector

I want to use the airflow 2.01 docker-compose file from apaches github.
here is the link docker-compose.yaml and here is the link to the dockerfiledockerfile
I want to use a Dag which should grab data out of my SQL Server database. Actually I get the following error:
no module named pymssql
After I manually installed it, I get an error like no module named pyodbc.
When I want to install this manually I get an gcc error, that it is not possible to install.
Does anyone have any clue about this?
Is there any docker-compose file which is able to handle SQL Server connection for Airflow 2?
Thanks in advance

PostgresSQL / pgAdmin4 / dump server version mismatch

I tried to make a backup with Postgres 11.1 in pgAdmin4, but it failed.
pgadmin displayed a window with
Status: Failed (exit code: 1).
pg_dump:server version: 11.1; pg_dump: 10.5
pg_dump: aborting because of server mismatch
I don't really understand it. Does pgadmin4 not know that I am using 11.1 and not 10.5?
PROBLEM SOLVED - IN MY CASE.
Go to
pgadmin < Preferences < Path < Binary Path
The PostgreSQL Binary Path was set automatically to $DIR/../runtime
I changed the Path to my installed PostgreSQL Version C:\Program Files\PostgreSQL\11\bin
Your pgAdmin is using PostgresSQL client v10, but your server is v11.
Since v10 cannot know how to correctly dump a v11 database, it refuses to try.
Use a more recent version of pgAdmin!

Call to undefined function sqlsrv_connect() using WAMP and php 7.1.6

First things first, I read and tried stuff I found online even from this website, but can't get it to work.
I have an SQL SERVER 2014 running on Windows Server 2012, there I have a WAMP 64 bits running Apache on PHP 7.1.6 and need to connect to the Database, apparently the extension is not loaded because I'm getting the undefined function error.
$conn = sqlsrv_connect( $APIDBSERVER, $connection);
What I've done so far:
Installed Microsoft® ODBC Driver 11 for SQL Server
Downloaded PHP SQL Driver 4.0 and moved php_sqlsrv_7_nts_x64.dll to /ext
Added them to php.ini:
extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_sqlsrv_7_nts_x64.dll
Apparently the PDO also needs php_pdo.dll which WAMP doesn't have and I haven't found where to download it from, so I'm using the standard non-PDO approach
Recently even tried enabling odbc extensions which were disabled:
extension=php_odbc.dll
extension=php_pdo_odbc.dll
I access the php.ini through the WAMP menu so I know I'm editing the right one, restarted the server several times trying different things but I've run out of ideas.
Can you please help me?
EDIT:
PHP error log indicates the modules couldn't be found, but if I check that path they're right there, copy&pasted filenames into php.ini.
PHP Warning: PHP Startup: Unable to load dynamic library
'c:/wamp64/bin/php/php7.1.6/ext/php_pdo_sqlsrv_7_nts_x64.dll' - The
specified module could not be found. in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'c:/wamp64/bin/php/php7.1.6/ext/php_sqlsrv_7_nts_x64.dll' - The
specified module could not be found. in Unknown on line 0
EDIT 2:
Tried downgrading to 7.0.20 and get the same error, so the php.ini is fine, it just won't load them for a reason, will try to download ODBC 13.1 maybe?
Each PHP version might require a different version of the Microsoft PHP Drivers for SQL Server.
The link below shows compatibility between PHP and MS SQLSRV versions:
https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15.
Because of the way WAMPServer is configures, NTS extensions do not run.
So change your process just a little and use the Thread safe dll's instead.

Laravel sql server on mac

So i installed SQL serve with docker on mac and i can actually manage to access my local sql server database with datagrip, but when i want to do a php artisan migrate i get this error:
[Illuminate\Database\QueryException] could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)
and this error
[PDOException]could not find driver
i search for some answer but they where mostly for linux.
So i manage to installed al the necessary drivers just by installing this:
https://github.com/Microsoft/msphpsql/releases
php and Laravel worked perfectly after i installed those package and added this lines on my php.ini file:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
You need a module called "pdo_mysql". Try php_info()to see if it's installed - I doubt it's there.
In your php.ini file (you can find it via php --ini) uncomment the line which has extension=pdo_mysql.so on it and restart the server.
edit: also make sure that the default key is set in your config/database.php file. Something like 'default' => env('DB_CONNECTION', 'mysql'),

PHP 7.x connection with MSSQL server with MAMP

I am trying to connect mssql server to PHP 7.0.8 through MAMP. I have tried using freetds. On some blog people are saying to use pdo_dblib.so extension but it's not working.
Please guide me through the process of connection.
For those who still have this problem:
/Applications/MAMP/bin/php/php7.2.1/bin/pecl install sqlsrv pdo_sqlsrv
Edit php.ini:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
If necessary, use brew install autoconf if you don't have it already.
While the answers posted by Vague Space and Pedro Santiago helped, I still think the answers are a bit lacking and incomplete… Or ask you to do too much. Honestly the official Microsoft instructions are overkill when they state you need to install their Docker image of SQL Server and such? C’mon… Most people just need the drivers installed to make a connection.
So here is my answer based on my experience installing the pdo_sqlsrv.so and sqlsrv.so modules in MAMP (version 5.2) but should work for most any MAMP version that supports some flavor of PHP 7.
Adjust the .bash_profile so MAMP’s binaries and libraries are a part of your $PATH settings.
First, adjust your .bash_profile so the MAMP stuff is in there; makes it easier to launch and work with MAMP specific binaries and ensures MAMP libraries are checked when doing things like installing new modules like this.
The way I like to do it is like this; set $MAMP_BIN and $MAMP_PHP variables like this and then rebuild the $PATH variables:
# MAMP stuff.
export MAMP_BIN="/Applications/MAMP/Library/bin";
export MAMP_PHP="/Applications/MAMP/bin/php/php7.2.10/bin";
# Final $PATH setting.
export PATH="/usr/local/bin:/usr/local/sbin:$MAMP_BIN:$MAMP_PHP:$PATH";
Save it and just log out of the Terminal session and back in, or just resource the .bash_profile like this:
source ~/.bash_profile
With that done, let’s install the core Microsoft ODBC binary stuff.
Install the Microsoft ODBC stuff.
Do this to install the core ODBC stuff on macOS; be sure to have Homebrew installed:
brew tap microsoft/SQLSRV-release https://github.com/Microsoft/homebrew-SQLSRV-release
brew update
brew install --no-sandbox msodbcsql17 SQLSRV-tools
Then when that’s done, go ahead and install the Unix ODBC stuff like this:
brew install unixodbc
Now install the actual PHP modules via PECL:
pecl install sqlsrv pdo_sqlsrv
With the modules installed, add them to the php.ini file in MAMP so PHP can recognize it. For PHP 7.2.10 on MAMP 5.x it should be located here:
/Applications/MAMP/bin/php/php7.2.10/conf/php.ini
And just add these config lines to the bottom of the file:
; Enable 'Microsoft Drivers for PHP for SQL Server' extension module
extension = sqlsrv.so
extension = pdo_sqlsrv.so
; Configuration
;sqlsrv.WarningsReturnAsErrors = 1
;sqlsrv.LogSeverity = 0
;sqlsrv.LogSubsystems = 0
;sqlsrv.ClientBufferMaxKBSize = 10240
;pdo_sqlsrv.log_severity = 0
;pdo_sqlsrv.client_buffer_max_kb_size = 10240
Note, most tutorials—and even PECL when you install the modules—simply mention adding extension = sqlsrv.so and extension = pdo_sqlsrv.so to the php.ini config, but these config options are the ones that RedHat has when installing the PHP SQLSRV via the Remi repo. Yeah, most of them are commented out but I still like having it there for reference.
Follow this guide through step 3: Microsoft PHP drivers for SQL Server
Find where pecl drops extensions in your local machine
Copy the files pdo_sqlsrv.so and sqlsrv.so into your MAMP's PHP extension directory. Mine was located at /Applications/MAMP/bin/php/php7x.x/lib/php/extensions/no-debug-foo-bar
Edit your php.ini file to include the new extensions:
extension=sqlsrv.so
extension=pdo_sqlsrv.so
Restart your MAMP servers.
having just done this in 2019 with MAMPPRO4 on windows 10 (follow upto step 4 to test that you are connected and then do point 9 ) point 5 onwards is for changing the path in the command line
download dll files from microsoft
https://www.microsoft.com/en-gb/download/details.aspx?id=20098
follow the instruction after running the exe file and place the dll
files into the extension directory of the php version that you are
using eg: MAMP/bin/php/php7.1.29/ext
check phpinfo for the Loaded Configuration File of the php.ini file
add the 2 dll files depending on your requirements (I wasted time by
using the 64.dll) make sure you are using ts(thread safe) not
nts(none thread safe) in the file name of the dll
extension=php_sqlsrv_71_ts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll
in control panel search for advanced system settings and click
click Environment Variables
under system variables not user variables click path and click edit
click new and add C:\MAMP\bin\php\php7.1.29 (Edit this to your path)
restart MAMP
open a new command line an enter php -v
you should see the php version displayed

Resources