Use odbc eloquent outside laravel PHP7 - php

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.

Related

How to install locally an extension in SQLite on a Mac?

I've no real knowledge about installing an extension. I'm stuck because I cannot use SQRT in SQLite.
I'm using Laravel on a local machine and I'm working on my PHPunit Tests. In one Test I'm using a query with some heavy math functions.
I get the error:
Caused by
PDOException: SQLSTATE[HY000]: General error: 1 no such function: SQRT
I found out that SQLite has an extension called: extension-functions.c
I downloaded it, but I'm not sure if I did everything correctly (obviously not because it does not work):
I downloaded it and used this in my terminal
gcc -fno-common -dynamiclib extension-functions.c -o libsqlitefunctions.dylib
It compiled this data: libsqlitefunctions.dylib
With php --ini if found that my php.ini is located in /usr/local/etc/php/7.1/php.ini
Now I looked up for sqlite3 and found this commented ;sqlite3.extension_dir =
I changed it to
sqlite3.extension_dir =/usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
and created the extension folder and put the dylib file inside
I restarted my apache with sudo apachectl restart
And tried my Query and still, it fails. What did I do wrong?
For future readers
To use it in Laravel you call it like this:
$pdo = DB::connection()->getPdo();
$pdo->sqliteCreateFunction('SQRT', 'sqrt', 1);
$pdo->sqliteCreateFunction('ASIN', 'asin', 1);
$pdo->sqliteCreateFunction('SIN', 'sin', 1);
$pdo->sqliteCreateFunction('COS', 'cos', 1);
$pdo->sqliteCreateFunction('POWER', 'pow', 2);
$pdo->sqliteCreateFunction('pi', 'pi', 0);
It seems that you want to use this with PDO. The problem is that loading extensions only works with the SQLite3 api directly, using the SQLite3::loadExtension method.
The PDO driver does not allow the loading of extensions (see this wiki entry regarding LoadableExtensions under "Security Considerations").
So you could either swith to the SQLite3 api directly or you could use "user defined functions" with PDO. For example if you need the SQRT function:
$db = new PDO('sqlite:testdb.sqlite', null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$db->sqliteCreateFunction('SQRT', 'sqrt', 1);
$stmt = $db->query("SELECT sqrt(25)");
foreach ($stmt as $row) {
echo $row[0], PHP_EOL; // output: 5.0
}
Most of the math-functions your extension provides map 1:1 to the PHP function names (like sqrt), so it should be easy to create the functions you need.
It seems you are pointing the sqlite3.extension_dir property at a file instead of a directory. According to the manual for sqlite3, the extension_dir property is:
[The] Path to the directory where the loadable extensions for SQLite reside.
I think it may work if you change
sqlite3.extension_dir = /usr/local/etc/php/7.1/extension/libsqlitefunctions.dylib
to
sqlite3.extension_dir = /usr/local/etc/php/7.1/extension
However, I would create a separate directory for the SQLite3 extensions so they are not mixed with the PHP extensions; I say this since it seems like you are currently using the PHP extension directory for the sqlite3.extension_dir property. (If you aren't, then please disregard this note.) I assume that SQLite3 just scans the configured directory for loadable modules and loads them using something like dlopen. This might conflict if it tries to load a PHP extension. (Who knows, it may gracefully handle this.)

ODBC Driver for Progess on Debian

All,
I am trying to install and get working the progress ODBC driver for Debian.
I have installed the progress driver no problem, however, when I try to connect in PHP using ODBC_Connect I get an error:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Can't open lib '/usr/dlc/odbc/lib/pgoe1022.so' : file not found, SQL state 01000 in SQLConnect
Next step was for me to see if the file existed and if that file had all of its dependencies.
So I issued the following command:
ldd /usr/dlc/odbc/lib/pgoe1022.so
And got the following:
linux-gate.so.1 => (0xb773e000)
libpthread.so.0 => /lib/i386-linux-gnu/i686/cmov/libpthread.so.0 (0xb7505000)
libpgicu22.so => not found
libdl.so.2 => /lib/i386-linux-gnu/i686/cmov/libdl.so.2 (0xb7500000)
libstdc++-libc6.2-2.so.3 => not found
libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xb74da000)
libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb7375000)
/lib/ld-linux.so.2 (0xb773f000)
Now I am stumped! I cannot get hold of the missing files.
Anyone able to assist at all please?
Regards
Col
It is always helpful to mention the versions of Progress, Linux, PHP and so forth that you are using.
Setting that aside for now. You say that you installed the ODBC driver "no problem". To confirm that you have done so and that the problem is external to the ODBC drivers you should first try a test connection with the supplied sqlexp utility.
From a Linux command shell start "proenv". This will properly set all the needed environment. Then run "sqlexp -u username -p password -db dbname -S port#"
That should get you a prompt where you can enter SQL queries etc.
If that works then you have all of the files needed from Progress' POV and the issue would be in your ODBC setup (odbc.ini). If it does not work then you likely have a Progress/OS release mismatch.

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.

Yiic migrate error due to pdo_mysql driver not found

I'm trying to learn Yii, but I'm stuck with a very persistent error that rises whenever I use yiic.
First system details: Ubuntu 13.04 with apache2, php 5.5.3 and mysql 5.5.3.
I run/yiic migrate
inside /protected of the webapp I'm developing.
I get the error:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/yii/framework/db/CDbConnection.php:382
Which seems to be because at line 382 of CDbConnection.php, the script checks if pod_mysql is installed, but can't find it.
`if($this->_pdo===null)
{
if(empty($this->connectionString))
throw new CDbException('CDbConnection.connectionString cannot be empty.');
try
{
Yii::trace('Opening DB connection','system.db.CDbConnection');
$this->_pdo=$this->createPdoInstance();
$this->initConnection($this->_pdo);
$this->_active=true;
}
catch(PDOException $e)
{
if(YII_DEBUG)
{
throw new CDbException('CDbConnection failed to open the DB connection:'.
$e->getMessage(),(int)$e->getCode(),$e->errorInfo);
}
else
{
Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
throw new CDbException('CDbConnection failed to open the DB connection.'
,(int)$e->getCode(),$e->errorInfo);
}
}
}
^^ Here is the relevant snippet of code.
The result of running
php -i|grep PDO gives
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled
So my problem seems to be that only the sqlite driver is running. However, I've ensured to check that php-mysql is installed (as pdo_mysql is deprecated and is inside this package). I've ran out of ideas on what to do, and will appreciate any and all help!!
Thanks in advance!
Console applications have their own config stored in protected/config/console.php. Please make sure you've got a database component configured there.
This problem is from your phpcli.ini instead of php.ini. in your phpcli.ini you should add :
extension=php_pdo_mysql.dll
as in php.ini

What are configs for Drupal7 + SQL Server using FreeTDS?

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' => ''
),
),

Categories