[PHP] Re: [PDO] Re: [PHP] PDO working via Apache but not at the command line?
Sounds like the error message "SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)" could be more informative, but I think this is returned by FreeTDS, not PDO. On Mon, Oct 18, 2010 at 7:35 PM, Scott Baker wrote: > On 10/18/2010 06:27 PM, Wez Furlong wrote: >> Things to check: >> >> - Environment: what env vars are set or not set in your Apache vs. CLI >> - Owner: are you running as the same user as your web server? >> - Do you or the web server have some kind of "rc" file that might impact >> how things run? > > Wez you're a genius. When I ran it as the same user as apache it works > fine. That got me thinking that it makes a log in /tmp. Checking the log > it was only writable by the apache user. A little chmod later and now my > script runs perfectly under apache and cli. > > Thanks for helping me think outside the box. I spent all day puzzled by > this, you just made my night. > > - Scott > > -- > PDO Working Group Mailing List (http://pdo.php.net) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PDO] Re: [PHP] PDO working via Apache but not at the command line?
On 10/18/2010 06:27 PM, Wez Furlong wrote: > Things to check: > > - Environment: what env vars are set or not set in your Apache vs. CLI > - Owner: are you running as the same user as your web server? > - Do you or the web server have some kind of "rc" file that might impact > how things run? Wez you're a genius. When I ran it as the same user as apache it works fine. That got me thinking that it makes a log in /tmp. Checking the log it was only writable by the apache user. A little chmod later and now my script runs perfectly under apache and cli. Thanks for helping me think outside the box. I spent all day puzzled by this, you just made my night. - Scott -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PDO] Re: [PHP] PDO working via Apache but not at the command line?
Things to check: - Environment: what env vars are set or not set in your Apache vs. CLI - Owner: are you running as the same user as your web server? - Do you or the web server have some kind of "rc" file that might impact how things run? Suggestion: Use "sudo -u webserverusername -s" to run a shell as your web server user, then try to run the CLI. Get the environment to match up with your webserver. If this still doesn't work, it might be something more esoteric; check to see if you have other apache modules loaded that might also use FreeTDS or ODBC and that might be messing with things. Use "strace php db-dump.php" to see what the CLI is up to. Use "strace -p " to see what the Apache version is up to (probably want to run apache -X to make this easier). --Wez. On Oct 18, 2010, at 5:26 PM, Scott Baker wrote: On 10/18/2010 02:17 PM, a...@ashleysheridan.co.uk wrote: 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. I didn't even think about it parsing different php.ini files. Checking the output of phpinfo() I see it's calling the same php.ini (/usr/local/lib/php.ini) though. :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO working via Apache but not at the command line?
On 10/18/2010 02:17 PM, a...@ashleysheridan.co.uk wrote: 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. I didn't even think about it parsing different php.ini files. Checking the output of phpinfo() I see it's calling the same php.ini (/usr/local/lib/php.ini) though. :( -- Scott Baker - Canby Telcom System Administrator - RHCE - 503.266.8253 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO working via Apache but not at the command line?
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" Date: Mon, Oct 18, 2010 21:20 Subject: [PHP] PDO working via Apache but not at the command line? To: , 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