It's most likely because both cli and web modules are using different php.ini config files. See what the output of a phpinfo() call in both browser and command line. Thanks, Ash http://www.ashleysheridan.co.uk ----- Reply message ----- From: "Scott Baker" <bakers@xxxxxxxxxxxx> Date: Mon, Oct 18, 2010 21:20 Subject: [PHP] PDO working via Apache but not at the command line? To: <pdo@xxxxxxxxxxxxx>, <php-general@xxxxxxxxxxxxx> I have the following very simple script that uses PDO/FreeTDS to connect to a mssql server. I have PHP Version 5.3.3 running on Linux under Apache. When I view this script via apache/firefox I get proper output. If I try and run this via the command line like "php db_dump.php" I get an error connecting to the DB: Unable to connect to Omnia: SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9). Does Apache call PHP differently than the cli would? Why would Apache method work find, but direct from the command line cause a problem? Do I need to call php from the cli with some other argument? ---------------------------------------------------------------------- $num || $num = 197804; $dbh = omnia_connect(); $sql = "EXECUTE P_SaaS_AccountServiceFeatures_Retrieve $num"; $sth = $dbh->prepare($sql); $sth->execute(); $foo = $sth->fetchAll(PDO::FETCH_ASSOC); foreach ($foo as $i) { if ($i['ItemStatus'] != 'I') { $out .= $i['Component'] . "\n"; } } print $out; #################################################################### function omnia_connect() { putenv('FREETDSCONF=/etc/freetds.conf'); $db = "DB_NAME"; $user = "user"; $pass = "pass"; $dsn = "dblib:host=Omnia;dbname=$db"; try { $dbh = new PDO($dsn, $user, $pass); } catch (PDOException $e) { echo 'Unable to connect to Omnia: ' . $e->getMessage(); exit; } return $dbh; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php