note 98716 added to ref.pdo-odbc

From: Date: Fri, 02 Jul 2010 11:03:38 +0000
Subject: note 98716 added to ref.pdo-odbc
Groups: php.notes 
Request: Send a blank email to php-notes+get-170650@lists.php.net to get a copy of this message
MSSQL - PHP on Apache - Linux Redhat When using php 5.2.10 please beaware of this error: http://bugs.php.net/bug.php?id=42068 Standard odbc_connect will not work, you must use pdo_odbc Connecting to MSSQL using pdo odbc - walkthrough.. 1. Download and configure FreeTDS with-unixodbc ./configure --prefix=/opt/SYSfreetds --with-unixodbc make;make test; make install 2. install php-odbc and unixODBC php-odbc-5.2.10-1.x86_64.rpm unixODBC.x86_64.x86x64 3. Setup ODBC links a) Create a tds.driver file with the following contents [FreeTDS] Description = v0.63 with protocol v8.0 Driver = /opt/SYSfreetds/lib/libtdsodbc.so Register the ODBC driver - the tds.driver file odbcinst -i -d -f tds.driver b) Creating a tds.datasource file - ODBC Data Source with contents: [SOURCENAME] Driver=FreeTDS Description=Test MS SQL Database with FreeTDS Trace=No Server=BobTheServer Port=1433 TDS Version=8.0 Database=youDBname Register the ODBC data source odbcinst -i -s -f tds.datasource Beware that the odbc.ini file will be installed in the current users home directory. This may need to be used if you are using a webserver as the apache home directory could be different. Ensure .odbc.ini is in apaches home directory, possibly "/var/www" 4. Test the ODBC link on the command line isql -v SOURCENAME 'username' 'password' +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> 5. Edit /etc/php.ini Make sure the following is set: mssql.secure_connection = On 6. Restart apache gracefully 7. PHP to run: <? $dbh= new PDO('odbc:SOURCENAME', 'username', 'password'); $stmt = $dbh->prepare("$query"); $stmt->execute(); while ($row = $stmt->fetch()) { print_r($row); } unset($dbh); unset($stmt); ?> Trouble-shooting: Please try strace/ truss if you encounter issues. It could be you are referencing wrong libraries somewhere. Ensure you have restarted apache once the odbc files are in place ---- Server IP: 192.41.42.26 Probable Submitter: 192.223.158.46 ---- Manual Page -- http://www.php.net/manual/en/ref.pdo-odbc.php Edit -- https://master.php.net/note/edit/98716 Del: integrated -- https://master.php.net/note/delete/98716/integrated Del: useless -- https://master.php.net/note/delete/98716/useless Del: bad code -- https://master.php.net/note/delete/98716/bad+code Del: spam -- https://master.php.net/note/delete/98716/spam Del: non-english -- https://master.php.net/note/delete/98716/non-english Del: in docs -- https://master.php.net/note/delete/98716/in+docs Del: other reasons-- https://master.php.net/note/delete/98716 Reject -- https://master.php.net/note/reject/98716 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170650) next »