What are configs for Drupal7 + SQL Server using FreeTDS? - php

we already have a Moodle installation working in this scenario: linux + php5 + freetds + sql server.
but we just can't figure out how to link drupal 7 to sql server in the same manner.
what configs should we use? anyone ever tried this?
drupal simply does not show up in the available databases list.
note: we are already able to connect php to sql server using freetds, but just can't figure out how to do this on Drupal 7.

You can't use sqlsrv module on Linux because it requires PDO_SQLSRV driver that works only on Windows (see this comment)
To use FreeTDS you will need to write a Drupal Database Driver by yourself (similar with sqlsrv). Or don't use the database abstraction layer at all and do the call by yourself inside your module (if you only need MS SQL for parts of you project.
The good news (I hope) is that you can install dblib driver (in Ubuntu: sudo apt-get install php5-mssql) and use the sandbox project. A little info regarding this sandbox projects you can find in author's comment here. How to use it in you settings.php file can be seen here.
dblib database support in Drupal is still experimental, so test it before using it.

No you can't, but you can use drupal odbc driver which works the same way but connect through odbc (https://www.drupal.org/sandbox/pstewart/2010758), all you have to do is to install it (including its server requirement) and change your configuration to something like this (tested on Drupal 7 on Ubuntu Server) :
'external' =>
array (
'default' =>
array (
'odbc_driver' => 'FreeTDS',
'database' => '',
'username' => '',
'password' => '',
'host' => '',
'port' => '1433',
'driver' => 'odbc',
'prefix' => ''
),
),

Related

CodeIgniter 3.1.9: Call to undefined function odbc_connect() in MacOS

UPDATE: This question has been flagged as a question that has been solved already. But when checked, those previous "similar" questions require users to download the corresponding .dll file which is not applicable for macOS users and other answers did not explicitly elaborate on how to install needed extensions like pdo_sqlsrv, sqlsrv, and ODBC for XAMPP-installed PHP.
I'm trying to connect to MS SQL database using CodeIgniter 3.1.9 via ODBC:
$db['default'] = array(
'dsn' => '',
'hostname' => 'x.x.x.x',
'username' => 'sa',
'password' => 'xxx',
'database' => 'xxx',
'dbdriver' => 'odbc'
But I'm getting this error:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function odbc_connect()
Filename: /Applications/XAMPP/xamppfiles/htdocs/gpweb/system/database/drivers/odbc/odbc_driver.php
Line Number: 141
PHP is installed via XAMPP. I checked the php.ini file to get information about ODBC and the line below is disabled because of the semi-colon in the beginning:
;extension=php_pdo_odbc.dll
I know it is irrelevant because I'm running on MacOS and .dll files are for Windows (but I still tried enabling it and with more errors):
A PHP Error was encountered
Severity: Core Warning
Message: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll, 0x0009): tried: '/Applications/XAMPP/xamppfiles/lib/php_pdo_odbc.dll' (no such file), '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll' (no such file)
Filename: Unknown
Line Number: 0
Has anyone encountered this issue before and how did you solve it? How can you enable ODBC in MacOS with PHP installed using XAMPP?
I found the solution, missing in php.ini
extension=php_odbc.dll
Unfortunately, macOS users that use XAMPP to install PHP have no way to install extensions like sqlsrv, pdo_sqlsrv, and ODBC, unlike in Windows, where they can download the necessary .dll files and enable extensions in the php.ini.
I've been using CodeIgniter 3.x.x for years to create web applications and MySQL as the database. I wanted to utilize the said PHP library with my other projects requiring MSSQL as the database since CI can do so, provided that you have installed the necessary extensions.
I have scoured the internet and there is really no definite solution to install extensions in XAMPP-installed PHP running macOS.
I gave up and installed PHP using homebrew instead. In your terminal, enter:
$ brew install php
Then installed sqlsrv extension (for M1 ARM64 users)
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install sqlsrv
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install pdo_sqlsrv
Then the ODBC extension:
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y
brew install msodbcsql17 mssql-tools
Since I cannot use the XAMPP-installed PHP, I have to use the CodeIgniter 4 to use the natively installed PHP:
composer create-project codeigniter4/appstarter project-root
After that, in the /project/app/Config/Database.php of my CodeIgniter 4 project, setup the connection to the database:
public $default = [
'DSN' => '',
'hostname' => 'x.x.x.x', // IP ADDRESS OF THE SQL SERVER
'username' => 'xxx', // USERNAME
'password' => 'xxx', // PASSWORD
'database' => 'xxx', // NAME OF DATABASE
'DBDriver' => 'SQLSRV', // DATABASE DRIVER TO BE USED
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 1433, // DEFAULT PORT FOR SQL SERVER
];
This is not the solution to the original problem (XAMPP-installed PHP), but an alternative solution to connect to MSSQL database using PHP.
REFERENCE:
https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16
https://www.codeigniter.com/user_guide/installation/index.html
But still, if you found a way to install sqlsrv and ODBC extensions in XAMPP-installed PHP running macOS, please don't hesitate to post it here.

Database Exception Could not find driver when connecting from PHP to MSSQL database on Mac / Unix system

First of all, I have tried searching through a lot of the same questions, but many of them are outdated or did not provide the results I need.
On my local machine, when running php -m, I get
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
When I run
echo "<h1>PDO drivers</h1><pre>", print_r(PDO::getAvailableDrivers()), "</pre>"; in a PHP file, I get
PDO drivers
Array
(
[0] => mysql
[1] => sqlite
[2] => pgsql
)
I have tried a lot of different drivers, but I found that it's best to use dblib for non-windows systems.
I open a connection with following code:
use yii\db\Connection;
$connection = new Connection([
//-> THIS ONE WORKS FOR MYSQL
//'dsn' => 'mysql:dbname=<testdb>;host=<testhost>;port=<port>',
//-> THIS ONE I'M TRYING TO GET WORKING
'dsn' => 'dblib:host=<windows MSSQL Server via tcp>;dbname=<db>',
'username' => '<user>',
'password' => '<pass>'
]);
$connection->open();
What do I need to do locally to get this running on my machine? I am running MAMP Pro.
I am a bit worried, because this PHP server is running on a Unix system and I will need to be able to get it working there as well.

Use odbc eloquent outside laravel PHP7

I am using eloquent outside laravel. I have my own PHP application.
This is what i am using https://github.com/illuminate/database
My config is as following
$settings3 = array(
'driver' => 'odbc',
'dsn' => "Driver={SQL Server};Server={serverName};Trusted_Connection=true;Database=telesur_mis;",
'username' => 'user',
'password' => 'user',);
$capsule->addConnection($settings3,'teleappframework');
After executing this code I am getting the following error
Fatal error: Uncaught InvalidArgumentException: Unsupported driver [odbc]
I have PDO ODBC installed, i have also tested pdo odbc connection outside of eloquent.
The reason for using ODBC is, because i am using PHP7 and currently there is no PDO extension for SQL Server.
Can anyone help me on this?
i would download FreeTDS and just use the regular sqlsrvr driver it works like a charm (if you are on a unix env) there is a lot of posts on how to configure it etc just look it up.
PHP7 has a few modules disabled by default that were previously enabled in PHP5.
Most likely running php -m does not show the modules you need.
It's an easy fix though since the extension should already exist in the \ext\ folder that came with PHP7. You just need to modify your php.ini file to include the line:
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Then from a command prompt or terminal test again using php -m to see that the module is now listed.

Cakephp cannot connect to sqlserver

I got this error :
CakePHP is NOT able to connect to the database.
Database connection "Sqlserver" is missing, or could not be created.
Details :
CakePHP 2.5.4
Wamp server 32-bit
Dreamweaver CS6
SQL Server 2014
On my details.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'host' => 'localhost\MSSQLSERVER',
'database' => 'testing'
);
I have load both the extension on both ext folder (apache & php) and on php.ini
extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll
Searched everywhere but still cannot connect to sqlserver.
note : I can connect to MySQL but not SQLServer
Maybe bacause you're not running sqlserver? Wamp is configured with apache/MySQL... hence the WAMP acronym...
In which case your config file should be similar to the one given in this example...
http://book.cakephp.org/2.0/en/development/configuration.html
Try to edit another php.ini in C:\wamp\bin\apache\Apache2.x.x\bin\ then restart apache.
Also the SQL Server Native Client must be installed for the extension to work.
In the end, i've found the solution. It's the problem of WAMPP server. Tho i have it installed on other machine and it works, it's not the same with the machine i'm currently using. So what i do is:
Uninstall WAMPP
Install XAMPP
Configure php.ini on apache and php
Load extensions in the ext folder of php
Note : I did the same configuration with WAMPP earlier
Then everything works like a charm.

using yii with memcache, error when one of two server fails

i have a problem with yii and storing data in memcache. For my application i use system.caching.CMemCache and the following config:
'servers' => array(
'server1' => array('host' => 'localhost', 'port' => 11211, 'weight' => 50),
'server2' => array('host' => '192.168.0.2', 'port' => 11211, 'weight' => 50)
),
if memcache on both systems is running, everything is ok and the values get spread up on the servers. but if one server fails (or if i stop the memcache manually) the application throw errors like
MemcachePool::get(): Server 192.168.0.2 (tcp 11211, udp 0) failed with: Connection refused (111)
this isn't really nice, i thought if one server failed yii would choose another server for reading and writing or at least produce some cache misses and do not throw an exeption :(
is this normal or are there some configuration issues?
I think its normal you are seeing those messages as discussed here, given you are using memcache extension
And also read this SO.
There are two version of extension for php one is memcache while the other is memcached. You can install each of them on ubuntu box like :
sudo apt-get install php5-memcache
and
sudo apt-get install php5-memcached
Memecached extension handles failover situations ,as I read from the above links and confirm by testing following settings in yii
'cache'=>array(
'class'=>'CMemCache',
'useMemcached'=>true,
'servers'=>array(
array(
'host'=>'localhost',
'port'=>11211,
'weight'=>60,
),
array(
'host'=>'192.168.33.31',
'port'=>11211,
'weight'=>30,
),
),
),
Install the memcached extension for php as described above and add 'useMemcached'=>true, setting to cache configs.As I test on my localhost, it handles the failover situation, but the page response time drops significantly.
Hope this will be helpful.
Is this variable true?
http://www.php.net/manual/en/memcache.ini.php#ini.memcache.allow-failover
Otherwise this link can also be useful:
Memcache : Confusions
(Probably this is only a notice.)

Categories