ODBC driver with Zend Server - php

I just installed the Zend Server on my system and I'm trying to test my database connections. I prefer using PDO to connect my databases.
MySQL connection works very well, but when I'm trying to connect MS SQL server I got an error.
Connection to MSSQL Server failed: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified
This is the code that I'm trying to run
try {
$pdo = new PDO('odbc:host=ip-addr; dbname=my-database', 'user', 'password');
echo "Successfully connected to MSSQL Server";
} catch (PDOException $e) {
echo "Connection to MSSQL Server failed: " . $e->getMessage();
}
I have successfully enabled odbc and pdo_odbc in the configuration panel. I'm running this on macOS Sierra 10.12.
Thanks in advance.

I found this tutorial, and it brought me to succeed. It's written for Linux, but I just installed Homebrew and followed the tutorial a bit adapting.

Related

How to connect from cakePHP3 to MSSQL Server

(I develop on a Windows System with XAMPP and use cakePHP3)
I want to connect from my cakePHP3 Localhost application, to a external SQL Server (installed on a external Windows Server 2012 r2).
In my app.php I config my Server and that is how I test the connection:
try {
$connection = ConnectionManager::get('sqlServer');
$connected = $connection->connect();
}catch (Exception $connectionError) {
echo "not";
}
echo "connected";
On testing I get this error:
A Database connection using was missing or unable to connect.
The database server returned this error: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
So I go to my Server and Installed the needed extensions (ODBC Driver 11 for SQL Server). But I get still the same Error.
Is it possible to connect to the external Server from Localhost? Or did I make a mistake?

install FreeTDC and unixODBC to connect SQL server using Laravel 5 - OS X El Capitan

I'm try to connect from php using laravel framewrok to SQL Server,
My php version is 5.5.30, PDO drivers installed are: mysql, sqlite, pgsql, odbc. using webServer (MAMP) in OS X El Capitan.
To connect i'm using FreeTDS and unixODBC, both libraries was installed using this articule. https://gist.github.com/Bouke/10454272
and work perfect from terminal.
I'm using the follow code in php file.
$db = new PDO('odbc:Driver=FreeTDS; Server=192.168.1.1; Port=4433; Database=focalyx; UID=myUser; PWD=myPassword;');
}
catch(PDOException $exception)
{
die("Unable to open database.<br />Error message:<br /><br />$exception.");
}
echo '<h1>Successfully connected!</h1>';
$query = 'SELECT * FROM Users';
try{
$statement = $db->prepare($query);
$statement->execute();
}catch(PDOException $exception){
die("Unable to open database.<br />Error message:<br /><br />$exception.");
}
$result = $statement->fetchAll(PDO::FETCH_NUM);
print_r($result);
however when try to run from localhost, show the this error.
exception 'PDOException' with message 'SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib 'FreeTDS' : file not found' in /Applications/MAMP/htdocs/myProject/test.php:5 Stack trace: #0 /Applications/MAMP/htdocs/myProject/test.php(5): PDO->__construct('odbc:Driver=Fre...') #1 {main}.
php is installed in
/Applications/MAMP/bin/php/php5.6.10/conf/php.ini
I don't know if is possible install FreeTDS into MAMP dir or create a kind of symbolic link.

PHP ODBC - connect to local .mdb database

I've installed the php5-odbc library.
Trying to connect to a .mdb file but keep getting error Data source name not found, and no default driver specified.
Code:
$dbName = "../../../var/Import/PartsPlaceDB.mdb";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");
Outputs:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in [...]
PDO Drivers:
foreach(PDO::getAvailableDrivers() as $driver)
{
echo $driver.'<br />';
}
Output:
mysql
odbc
sqlite
The problem is recurrent with 64-bit version. It looks like your code only work on Windows 32-bit.
To solve the problem, you might install this tool: Microsoft Access Database Engine 2010 Redistributable. I had the same problem for months but this tool solved mine.
I guess you're doing the location wrong?
Instead of this
$dbName = "../../../var/Import/PartsPlaceDB.mdb";
Why not do it like this
$dbName = "..\..\..\var\Import\PartsPlaceDB.mdb";

PHP + PDO ODBC Connection error

I am using PHP to connect to an MS access .accdb using the following connection
try {
$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb,
*.accdb)};Dbq=C:\\xampp\\htdocs\\seedOnline\\db\\seed12c.accdb;Pwd=");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) { //if connection fails
echo 'Seed Database Connection failed: ' . $e->getMessage();
}
This program works on two different computers with Xampp and Apache in our office, but when copying the entire program to new computers it failswith the following error:
Seed Database Connection failed: SQLSTATE[IM002] SQLDriverConnect:
0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Here is line 34:
foreach ($conn->query($qryUsers) as $qryUsersRow) {
The query $qryUsers is :
$qryUsers = "SELECT * FROM tblPwd";
and the table does exist.
Any particular configuration that I may be missing? All machines are windows 8.1 64 bit.

Connect PHP to UniVerse ODBC DSN

I have what seems a simple question, but I just cant get php to connect to my ODBC DSN.
I have a webserver with an ODBC DSN configured properly, I can test the connection and it works just fine.
I am now trying to connect PHP to this DSN.
MYDSNNAME is using the driver: UniVerse 64-Bit ODBC Driver.
Here is my php code:
$conn=odbc_connect('MYDSNNAME','username','password',SQL_CUR_USE_ODBC);
if (!$conn)
{
exit("Connection Failed: " . $conn);
}
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}
dbc_close($conn);
I am getting the following error:
Message: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect
I have tried using the 64bit ODBC administrator and that did not work. Any suggestions would be great.
Thanks
I was able to circumvent the error I was getting by using the 32bit version of the driver within my ODBC Administrator and I am now connecting just fine.
It gets a little tricky with 32/64bit versions of the odbc administrator.

Categories