MsSql/odbc driver now showing when set up on Ubuntu(Linux) - php

I have been trying to get MsSQL recognised on my linux based web server which currently has Ubuntu installed on it. I have followed the steps shown on this post but i have not managed to get it to work:
Connect PHP to MSSQL via PDO ODBC
Everytime i run the following command in PHP i simply ohly get mysql as though it only picks up the mysql.so file:
foreach (PDO::getAvailableDrivers() as $driver)
{
echo $driver . '<br />';
}
Does anybody know how i can get it to output the odbc driver also? The reason i ask is because the PHP application i am trying to run has the following code in it which i am trying to get around as it's written for Microsoft Server by the looks of it:
if (extension_loaded('pdo_sqlsrv')) $this->extension = 'pdo_sqlsrv';
else if (extension_loaded('pdo_odbc')) $this->extension = 'pdo_odbc';
If i comment the above code out the pdo statement doesn't connect for the reason i mentioned above due to no odbc driver
I tried to install freetds and configure it but i couldn't get it working as odbc doesn't show in the drivers list;
Reading package lists... Done
Building dependency tree
Reading state information... Done
tdsodbc is already the newest version.
unixodbc is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 171 not to upgrade.
anybody got any suggestions on reading from MsSQL with PHP 5.4 on linux (Ubtuntu)?

Ok so i managed to get a stage further. I got the ODBC linux driver working and now i have hit another problem: SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source <---does this mean that the port needs to be forwarded or that the username and password i have is incorrect? I assume this means that the driver is ok? when i try a tsql it just seems to time out after 60 seconds

Related

Connecting Laravel with SQL Server database always shows error "could not find driver"

I want to connect Laravel (version 8), with a SQL Server database (SQL Server 2008 R2).
I've done the installation and followed some tutorials with steps like the following, where the version I installed adapts to SQL Server 2008 R2, like this guide :
Installed Microsoft® ODBC Driver 17 for SQL Server (I chose version 17 because of this)
Installed PHP Driver version 5.6 by taking 2 files, namely php_pdo_sqlsrv_73_ts.dll and php_sqlsrv_73_ts.dll which I got from here (I chose version 5.6 based on this)
I put the above 2 files in C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext
I enabled the extension in php.ini, like this: extension=pdo_sqlsrv_73_ts,
extension=sqlsrv_73_ts. It succeed, When I checked in php.info, it says pdo_sqlsrv
Then I configured the database connection on Laravel's .env like this (I've created a database with that name):
DB_CONNECTION=sqlsrv
DB_HOST=192.168.101.103:86
DB_PORT=1433
DB_DATABASE=testlaravel
DB_USERNAME=faisallocal
DB_PASSWORD=faisallocal
Then I run php artisan migrate on terminal.
But I always get an error like this:
[Illuminate\Database\QueryException
could not find driver (SQL: select * from sys.sysobjects where id =
object_id(migrations) and xtype in ('U', 'V'))
at
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
708▕ // If an exception occurs when trying to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) { 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e 714▕ );
715▕ }
716▕ }
1
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDOException::("could not find driver")
2
C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
PDO::__construct("dblib:host=192.168.101.103:86:1433;dbname=testlaravel;charset=utf8",
"faisallocal", "faisallocal", [])]
What did I miss?
I did this test locally, and I have XAMPP as well as Laragon with different versions, but wouldn't it be okay if I had a different port?
Please help anyone who has experience and has advice on this, I've been stuck at this point for weeks..
Thank you
php_pdo_sqlsrv_73_ts.dll It depends of your version of php
for example: php_pdo_sqlsrv_73_ts.dll is for php 7.3
in the next link you can see this information.
https://learn.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15
So this all happened because of the detected different versions of PHP and SQL Server drivers.
For information, I have 3 local servers, namely:
XAMPP 1.7.3,
3,, (I forgot the version details),
and Laragon.
The problem that occurs is, when I want to develop apps using the Laragon server AND I use the local Terminal/Command Prompt (Shortcut: Windows + CMD), the PHP versions from other local servers will collide with each other.
When I run a Laravel command, check the PHP version, or whatever, the local Command Prompt directs me to the version of XAMPP above that I have installed, so any .dll or plugins you install in Laragon won't be detected!
Finally I was able to finish my installation and do a lot of CMD commands according to the version I want, is how to use the built-in CMD/Terminal from Laragon (Click on Terminal under Laragon application)
From this Terminal, all the .dll plugins that you install, and all the cmd commands that you enter, will match the Laragon version you are using, they won't be strayed to another local server! :D

Getting error messages while connecting to snowflake database though ODBC

I am using Ubuntu, I am trying to connect php to snowflake using ODBC driver, I have added driver information in /etc/odbcinst.ini. Here is the driver information, that I am using
[ODBC Drivers]
SnowflakeDSIIDriver=Installed
[SnowflakeDSIIDriver]
APILevel=1
ConnectFunctions=YYY
Description=Snowflake DSII
Driver=path-to-"libSnowflake.so"
DriverODBCVer=03.52
SQLLevel=1
ErrorMessagesPath=path-to-folder-which-has-error-message-xml-files
I am getting error two erros
The error 1 : SFRestRequestFailed could not be found in the en-US locale. Check that /en-US/SFMessages.xml exists.
The error 2 : REST request to the Snowflake is failing(I got this error by checking corresponding message attached to 'SFRestRequestFailed' in SFMessages.xml).
But I am able to connect Snowflake and fetch data using same access details in windows.
Kindly share your ideas to resolve this issue.
Thank you
ErrorMessagePath is a snowflake configuration. If you use the snowflake odbc package for linux, you will find unixodbc.snowflake.ini or iodbc.snowflake.ini which you can use accordingly depending on which driver manager you are using. ErrorMessagePath should be set in unixodbc.snowflake.ini or iodbc.snowflake.ini and your SIMBAINI env var should be set to point to one of these files.

Could not connect to the database. Connector returned number: Database sqlsrv_connect failed

I am unable to connect Joomla to MSSQL
I keep getting
Could not connect to the database. Connector returned number: Database
sqlsrv_connect failed
Whether I use the MySQLi driver or the drivers I installed (Microsoft SQL Server)
Seems like driver installation issue ,
I am able to connect to the same box with Mssql Client fine...
Can someone post an explanation on how to install MSSQL drivers for Joomla on PHP from scratch?
Or send an up to date reference on how to do this?
Joomla 3.4
PHP 5.6
IIS 7.5
MSSQL 2008 R2
If I switch the driver to: php_sqlsrv_54_ts.dll - it will disperser from the "database type" in joomla installer..
Thank you
The joomla error that is displayed is misleading and not quite useful.
So first step would be to modify the joomla code to find out the exact error.
Modify the following code in connect() function in your application's root directory
libraries\joomla\database\driver\sqlsrv.php
From
// Attempt to connect to the server.
if (!($this->connection = # sqlsrv_connect($this->options['host'], $config)))
{
throw new RuntimeException('Database sqlsrv_connect failed');
}
To
// Attempt to connect to the server.
if (!($this->connection = # sqlsrv_connect($this->options['host'], $config)))
{
throw new RuntimeException("Database sqlsrv_connect failed - Error : ".print_r( sqlsrv_errors(), true));
}
This will give you the exact error and guide you with the next steps needed.
Another thing to consider during SQL server installation is to enable the SQL server authentication as Joomla uses SQL server authentication by default.
You can confirm that Joomla uses SQL server authentication by checking in the same function in the same file as mentioned above
$config = array(
'Database' => $this->options['database'],
'uid' => $this->options['user'],
'pwd' => $this->options['password'],
'CharacterSet' => 'UTF-8',
'ReturnDatesAsStrings' => true);
Here is the PHP manual that confirms the same.
http://php.net/manual/en/function.sqlsrv-connect.php
You can enable SQL server authentication either during installation or post installation from the manamgement studio.
Hope this helps.
Download SQLServer 2008 Express, SQLServer 2008 Standard/Enterprise
editions (R2 or later)
Download PHP Drivers
Download SQLSRV20.EXE to a temporary directory
Run SQLSRV20.EXE
When prompted, enter the path to the PHP extensions directory
If you are using some sort of LAMP stack like XAMPP
Copy php_sqlsrv_52_ts_vc6.dll to php/ext folder
Make an entry in php.ini as follows
Extension=php_sqlsrv_52_ts_vc6.dll
Note:
If you need PDO or vc9 versions - please copy the "ts" version
appropriate for your needs.
If you are using IIS with PHP engine installed via FAST-CGI - please
make the appropriate changes in c:\Program Files\php\php.ini and
copy the dll to c:\Program Files\php\ext folder
Now - You can install Joomla 2.5 by selecting the SQLServer 2008 from the dropdown list in the step 4 of the installation.
After installation is complete - continue navigation around the administrator/site

Making ODBC Driver 11 for SQL Server Available For PHP In Azure Website

I have a PHP 5.5 website running WordPress in Azure Websites configured to run with 64-bit IIS, with the database running in MySQL. I want to convert the site to use SQL Server in Azure instead of MySQL.
I've installed the WP Db Abstraction plugin, and followed its setup instructions. I've elected to use the sqlsrv driver, so I've installed the Microsoft Drivers for PHP for SQL Server 3.1 and added them into a folder in the WordPress website and configured them as an extension. Calling phpinfo() on a test page shows that the sqlsrv driver has been loaded into PHP, and also reports that PHP is x86.
I've also setup the database, user and password and tested that I can connect to it successfully using SQLCMD.
The Microsoft Drivers for PHP for SQL Server 3.1 instructions state that the "Microsoft ODBC Driver 11 for SQL Server version 11" is also required. I've downloaded the x64 and x86 versions and tried the DLLs out of the relevant Windows directories and added them to the extension directory alongside the PHP drivers for both architectures but neither has worked.
When trying to connect to the SQL Azure Database from the running PHP site, I just get this error:
This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
The DLL files for the drivers I have relative to the WordPress site root are:
ext\msodbcsql11.dll
ext\php_sqlsrv_55_nts.dll
ext\1033\msodbcsqlr11.rll
I have the following set in the Azure Management Portal for the website for the App Settings:
PHP_EXTENSIONS:ext\php_sqlsrv_55_nts.dll
All I can figure is that I'm either missing something from the ODBC drivers, or how I'm going about making them available to the PHP driver is incorrect.
Does anyone have any ideas as to what I've missed, or why this isn't working?
Below is the test code I'm using to test the SQL Server connectivity in PHP.
<?php
$serverName = "MYSERVER.database.windows.net,1433";
$connOptions = array("UID"=>"MYUSERNAME", "PWD"=>"MYPASSWORD");
$conn = sqlsrv_connect( $serverName, $connOptions );
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true));
}
if( $client_info = sqlsrv_client_info( $conn)) {
foreach( $client_info as $key => $value) {
echo $key.": ".$value."<br />";
}
} else {
echo "Error in retrieving client info.<br />";
}
?>
I didn't really find a proper solution to this in the end, but it turned out that all the bits for using SQL Server with PHP 5.4 are already installed in Azure Websites.
I downgraded from PHP 5.5 to 5.4 and then SQL Server connectivity started working.
Not really a fix, but it's gotten me to the position (mostly) that I wanted.

Php - Ingres, fresh install : How to debug?

I just finished to install Ingres on my server(only the client part, to connect to an existing ingres server), I just added the php_ingres module.
Now php recognize my module, so I tried to connect my self to several existing servers, but I always a
Unable to connect to database (Hostname here)
But with this I can't find what is wrong?? ingres error? Php driver? Credentials? ...?
What can I do to isolate these problem?
Most likely it's a user credentials issue. To see the actual error message use the following code:
$connection = ingres_connect(.....);
if (!is_resource($connection))
{
trigger_error(ingres_errno()." - ". ingres_error(),E_USER_ERROR);
}
You might also want to take a look at http://community.ingres.com/wiki/Ingres_with_Apache_on_Debian_Etch which outlines the setup steps for Ingres, PHP, Apache and Debian/Ubuntu.

Categories