Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Mark Halling-Brown

Thanks for your replies.
In my desperation, I declared those environment variables in as many  
places as I could think of. The script (Although I know I shouldnt),  
php.ini and also the apache httpd.conf file:


SetEnv ORACLE_HOME /opt/oracle/instanceclient
SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv ORACLE_BASE /opt/oracle/instanceclient

But given that it works on the command line, but not through the  
browser, I think that the environment variables must be set correctly.


Cheers
Mark


On 16 Mar 2009, at 1:26 AM, Christopher Jones wrote:




Chris wrote:
   Warning: ocilogon() [function.ocilogon]: OCIEnvNlsCreate()  
failed. There is something wrong with your system - please check  
that LD_LIBRARY_PATH includes the directory with Oracle  
Instant Client libraries in/Library/WebServer/Documents/oracle.php  
on line 25   Oracle Connect Error

snip

putenv(LD_LIBRARY_PATH=/opt/oracle/instanceclient);
I'd guess you probably need this in apache's start up script, not  
in php (where that is on a mac setup I have no idea).

You could also try it in your virtual host:
http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient


I agree that using putenv() for Environment variables in scripts is  
bad.

On Mac, I think you need DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH.
See http://www.oracle.com/technology/pub/articles/bibbs-php-leopard.html

Chris

--
Email: christopher.jo...@oracle.com  Tel: +1 650 506 8630
Twitter:  http://twitter.com/ghrdFree PHP Book: http://tinyurl.com/UGPOM


_

Mark Halling-Brown
Higher Scientific Officer,
Computational Biology  Chemogenomics, Cancer Therapeutics,
The Institute of Cancer Research
15 Cotswold Road
Belmont, Surrey SM2 5NG, UK
Tel: (+44)-20-8722-4300 (ext: 4659)
Email: mhallingbr...@icr.ac.uk
Web: http://www.markyhb.co.uk

A cynic is what an idealist calls a realist


The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only.  If the 
message is received by anyone other than the addressee, please return the 
message to the sender by replying to it and then delete the message from your 
computer and network.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread chris smith
On Mon, Mar 16, 2009 at 6:51 PM, Mark Halling-Brown
mhallingbr...@icr.ac.uk wrote:
 Thanks for your replies.
 In my desperation, I declared those environment variables in as many places
 as I could think of. The script (Although I know I shouldnt), php.ini and
 also the apache httpd.conf file:

 SetEnv ORACLE_HOME /opt/oracle/instanceclient
 SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
 SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
 SetEnv ORACLE_BASE /opt/oracle/instanceclient

 But given that it works on the command line, but not through the browser, I
 think that the environment variables must be set correctly.

Did you restart apache after doing this?

The env variables are set correctly for your user, but not apache's
(which is the problem).

Does the mac have an /etc/environment file? That should cover all users.

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Mark Halling-Brown


Did you restart apache after doing this?


Yes, many times



The env variables are set correctly for your user, but not apache's
(which is the problem).


Indeed, I have removed the putenv declarations in the php script and  
inserted this:

echo(Using LD_LIBRARY_PATH: . getenv(LD_LIBRARY_PATH));
echo , ORACLE_HOME=.getenv(ORACLE_HOME);
echo(, DYLD_LIBRARY_PATH: . getenv(DYLD_LIBRARY_PATH));

And it prints to the screen (browser) correctly:
Using LD_LIBRARY_PATH: /opt/oracle/instanceclient, ORACLE_HOME=/opt/ 
oracle/instanceclient, DYLD_LIBRARY_PATH: /opt/oracle/instanceclient


For completeness, I have also put the variables is /etc/profile, /etc/ 
bash_profile etc


So it seems that the variables are set up for sure (unless this is  
just for php, but I do have these variables in the apache httpd.conf)


This is a puzzler
Cheers
Mark





Does the mac have an /etc/environment file? That should cover all  
users.


--
Postgresql  php tutorials
http://www.designmagick.com/


_

Mark Halling-Brown
Higher Scientific Officer,
Computational Biology  Chemogenomics, Cancer Therapeutics,
The Institute of Cancer Research
15 Cotswold Road
Belmont, Surrey SM2 5NG, UK
Tel: (+44)-20-8722-4300 (ext: 4659)
Email: mhallingbr...@icr.ac.uk
Web: http://www.markyhb.co.uk

A cynic is what an idealist calls a realist



The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only.  If the 
message is received by anyone other than the addressee, please return the 
message to the sender by replying to it and then delete the message from your 
computer and network.

Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Grant Croker

On/El 16/03/09 09:23, chris smith wrote/escribió:

On Mon, Mar 16, 2009 at 6:51 PM, Mark Halling-Brown
mhallingbr...@icr.ac.uk  wrote:
   

Thanks for your replies.
In my desperation, I declared those environment variables in as many places
as I could think of. The script (Although I know I shouldnt), php.ini and
also the apache httpd.conf file:

SetEnv ORACLE_HOME /opt/oracle/instanceclient
SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv ORACLE_BASE /opt/oracle/instanceclient

But given that it works on the command line, but not through the browser, I
think that the environment variables must be set correctly.
 


Did you restart apache after doing this?

The env variables are set correctly for your user, but not apache's
(which is the problem).

   
Does the mac have an /etc/environment file? That should cover all users.


Unfortunately not although with the stock/supplied Apache web server 
there is a plist file you can edit to add environment settings. Edit 
|/System/Library/LaunchDaemons/org.apache.httpd.plist, adding the 
relevant environment variable key/value information:|


?xml version=1.0 encoding=UTF-8?
!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN 
http://www.apple.com/DTDs/PropertyList-1.0.dtd;

plist version=1.0
dict
keyEnvironmentVariables/key
dict
keyDYLD_LIBRARY_PATH/key
stringpath goes here/string
keyORACLE_HOME/key
stringpath goes here/string
keyORACLE_BASE/key
stringpath goes here/string
/dict
keyLabel/key
stringorg.apache.httpd/string
.
.
.
/dict
/plist


Then you use PassEnv in Apache to pass these values through to PHP. The 
SetEnv directive in Apache is not the same as setenv or export in 
csh/bash/etc. Apache maintains its own symbol table for environment 
variables. Unless the OCI8 extension calls apache_getenv those 
declarations will have no effect.


regards

grant

--
Grant Croker - Ingres PHP and Ruby maintainer
http://blogs.planetingres.org/grant
Generally, old media don't die. They just have to grow old gracefully.
Guess what, we still have stone masons. They haven't been the primary
purveyors of the written word for a while now of course, but they still
have a role because you wouldn't want a TV screen on your headstone.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Mark Halling-Brown

Hi Grant,

Thanks to your instructions, I am making a bit of progress.
I have entered the PassEnv commands into the https.conf.:
SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
PassEnv DYLD_LIBRARY_PATH
PassEnv LD_LIBRARY_PATH

It now seems that this variable is passed through correctly, but it is  
not as I set it. Instead it states:

DYLD_LIBRARY_PATH: /usr/local/apache2/lib:

I restart apache as root user (sudo /usr/local/apache2/bin/apachectl  
restart) and it complains that:
[Mon Mar 16 11:08:53 2009] [warn] PassEnv variable LD_LIBRARY_PATH was  
undefined


 So I am guessing that root has not picked up any of the environment  
variables that I have set in various places around my system. I have  
put DYLD_LIBRARY_PATH in /etc/bashrc ~/.bash_profileetc, but I still  
seems root doesn't know about them.


Have you any idea where I need to set these variables (Is there a root  
home directory I can edit a .bash_profile or something?)


I did edit the /System/Library/LaunchDaemons/org.apache.httpd.plist  
file, but the apache I am using was compiled from source, so I fear it  
wont work list that plist?


Thanks for all your help
Mark


On 16 Mar 2009, at 10:27 AM, Grant Croker wrote:


On/El 16/03/09 09:23, chris smith wrote/escribió:

On Mon, Mar 16, 2009 at 6:51 PM, Mark Halling-Brown
mhallingbr...@icr.ac.uk  wrote:


Thanks for your replies.
In my desperation, I declared those environment variables in as  
many places
as I could think of. The script (Although I know I shouldnt),  
php.ini and

also the apache httpd.conf file:

SetEnv ORACLE_HOME /opt/oracle/instanceclient
SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv ORACLE_BASE /opt/oracle/instanceclient

But given that it works on the command line, but not through the  
browser, I

think that the environment variables must be set correctly.



Did you restart apache after doing this?

The env variables are set correctly for your user, but not apache's
(which is the problem).

  Does the mac have an /etc/environment file? That should cover all  
users.


Unfortunately not although with the stock/supplied Apache web server  
there is a plist file you can edit to add environment settings. Edit  
|/System/Library/LaunchDaemons/org.apache.httpd.plist, adding the  
relevant environment variable key/value information:|


?xml version=1.0 encoding=UTF-8?
!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd 


plist version=1.0
dict
keyEnvironmentVariables/key
dict
keyDYLD_LIBRARY_PATH/key
stringpath goes here/string
keyORACLE_HOME/key
stringpath goes here/string
keyORACLE_BASE/key
stringpath goes here/string
/dict
keyLabel/key
stringorg.apache.httpd/string
   .
   .
   .
/dict
/plist


Then you use PassEnv in Apache to pass these values through to PHP.  
The SetEnv directive in Apache is not the same as setenv or  
export in csh/bash/etc. Apache maintains its own symbol table for  
environment variables. Unless the OCI8 extension calls apache_getenv  
those declarations will have no effect.


regards

grant

--
Grant Croker - Ingres PHP and Ruby maintainer
http://blogs.planetingres.org/grant
Generally, old media don't die. They just have to grow old gracefully.
Guess what, we still have stone masons. They haven't been the primary
purveyors of the written word for a while now of course, but they  
still

have a role because you wouldn't want a TV screen on your headstone.



_

Mark Halling-Brown
Higher Scientific Officer,
Computational Biology  Chemogenomics, Cancer Therapeutics,
The Institute of Cancer Research
15 Cotswold Road
Belmont, Surrey SM2 5NG, UK
Tel: (+44)-20-8722-4300 (ext: 4659)
Email: mhallingbr...@icr.ac.uk
Web: http://www.markyhb.co.uk

A cynic is what an idealist calls a realist


The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only.  If the 
message is received by anyone other than the addressee, please return the 
message to the sender by replying to it and then delete the message from your 
computer and network.

Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Grant Croker

Hi Mark,

you are right /System/Library/LaunchDaemons/org.apache.httpd.plist will 
not work in your case, it's for the Mac OS X supplied Apache. In your 
case you can edit /usr/local/apache2/bin/apachectl adding the following:


DYLD_LIBRARY_PATH=/opt/oracle/instanceclient
LD_LIBRARY_PATH=/opt/oracle/instanceclient
ORACLE_BASE=/opt/oracle/instanceclient
ORACLE_HOME=/opt/oracle/instanceclient
export DYLD_LIBRARY_PATH LD_LIBRARY_PATH ORACLE_BASE ORACLE_HOME

(note: As Chris Jones mentioned LD_LIBRARY_PATH is not used on OS X, 
however there is no harm in having it set)


Place the above some where near the top of apachectl, I cannot tell you 
exactly since fink will not install and MacPorts does not build SQLite3. 
Restart apache and you should see the correct values in getenv() or 
phpinfo().


regards

grant


On/El 16/03/09 12:13, Mark Halling-Brown wrote/escribió:

Hi Grant,

Thanks to your instructions, I am making a bit of progress.
I have entered the PassEnv commands into the https.conf.:
SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
PassEnv DYLD_LIBRARY_PATH
PassEnv LD_LIBRARY_PATH

It now seems that this variable is passed through correctly, but it is 
not as I set it. Instead it states:

DYLD_LIBRARY_PATH: /usr/local/apache2/lib:

I restart apache as root user (sudo /usr/local/apache2/bin/apachectl 
restart) and it complains that:
[Mon Mar 16 11:08:53 2009] [warn] PassEnv variable LD_LIBRARY_PATH was 
undefined


 So I am guessing that root has not picked up any of 
the environment variables that I have set in various places around my 
system. I have put DYLD_LIBRARY_PATH in /etc/bashrc 
~/.bash_profileetc, but I still seems root doesn't know about them.


Have you any idea where I need to set these variables (Is there a root 
home directory I can edit a bash_profile or something?)


I did edit the /System/Library/LaunchDaemons/org.apache.httpd.plist 
file, but the apache I am using was compiled from source, so I fear it 
wont work list that plist?


Thanks for all your help
Mark




--
Grant Croker - Ingres PHP and Ruby maintainer
http://blogs.planetingres.org/grant
It was so much easier to blame it on Them. It was bleakly depressing to think 
that They were Us. If it was Them, then nothing was anyone's fault. If it was 
us, what did that make Me? After all, I'm one of Us. I must be. I've certainly 
never thought of myself as one of Them. No one ever thinks of themselves as one 
of Them. We're always one of Us. It's Them that do the bad things.
-- Terry Pratchett, Jingo



Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Mark Halling-Brown

Grant, thank you very much. You are a life saver. This worked perfectly.

Thanks again
Mark



On 16 Mar 2009, at 11:53 AM, Grant Croker wrote:


Hi Mark,

you are right /System/Library/LaunchDaemons/org.apache.httpd.plist  
will not work in your case, it's for the Mac OS X supplied Apache.  
In your case you can edit /usr/local/apache2/bin/apachectl adding  
the following:


DYLD_LIBRARY_PATH=/opt/oracle/instanceclient
LD_LIBRARY_PATH=/opt/oracle/instanceclient
ORACLE_BASE=/opt/oracle/instanceclient
ORACLE_HOME=/opt/oracle/instanceclient
export DYLD_LIBRARY_PATH LD_LIBRARY_PATH ORACLE_BASE ORACLE_HOME

(note: As Chris Jones mentioned LD_LIBRARY_PATH is not used on OS X,  
however there is no harm in having it set)


Place the above some where near the top of apachectl, I cannot tell  
you exactly since fink will not install and MacPorts does not build  
SQLite3. Restart apache and you should see the correct values in  
getenv() or phpinfo().


regards

grant


On/El 16/03/09 12:13, Mark Halling-Brown wrote/escribió:

Hi Grant,

Thanks to your instructions, I am making a bit of progress.
I have entered the PassEnv commands into the https.conf.:
SetEnv DYLD_LIBRARY_PATH /opt/oracle/instanceclient
SetEnv LD_LIBRARY_PATH /opt/oracle/instanceclient
PassEnv DYLD_LIBRARY_PATH
PassEnv LD_LIBRARY_PATH

It now seems that this variable is passed through correctly, but it  
is not as I set it. Instead it states:

DYLD_LIBRARY_PATH: /usr/local/apache2/lib:

I restart apache as root user (sudo /usr/local/apache2/bin/ 
apachectl restart) and it complains that:
[Mon Mar 16 11:08:53 2009] [warn] PassEnv variable LD_LIBRARY_PATH  
was undefined


So I am guessing that root has not picked up any of the environment  
variables that I have set in various places around my system. I  
have put DYLD_LIBRARY_PATH in /etc/bashrc ~/.bash_profileetc, but I  
still seems root doesn't know about them.


Have you any idea where I need to set these variables (Is there a  
root home directory I can edit a bash_profile or something?)


I did edit the /System/Library/LaunchDaemons/org.apache.httpd.plist  
file, but the apache I am using was compiled from source, so I fear  
it wont work list that plist?


Thanks for all your help
Mark




--
Grant Croker - Ingres PHP and Ruby maintainer
http://blogs.planetingres.org/grant
It was so much easier to blame it on Them. It was bleakly depressing  
to think that They were Us. If it was Them, then nothing was  
anyone's fault. If it was us, what did that make Me? After all, I'm  
one of Us. I must be. I've certainly never thought of myself as one  
of Them. No one ever thinks of themselves as one of Them. We're  
always one of Us. It's Them that do the bad things.

   -- Terry Pratchett, Jingo



_

Mark Halling-Brown
Higher Scientific Officer,
Computational Biology  Chemogenomics, Cancer Therapeutics,
The Institute of Cancer Research
15 Cotswold Road
Belmont, Surrey SM2 5NG, UK
Tel: (+44)-20-8722-4300 (ext: 4659)
Email: mhallingbr...@icr.ac.uk
Web: http://www.markyhb.co.uk

A cynic is what an idealist calls a realist


The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company 
Limited by Guarantee, Registered in England under Company No. 534147 with its 
Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only.  If the 
message is received by anyone other than the addressee, please return the 
message to the sender by replying to it and then delete the message from your 
computer and network.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Php, Oracle on Mac, with strange behaviour

2009-03-16 Thread Christopher Jones


Grant Croker wrote:
 DYLD_LIBRARY_PATH=/opt/oracle/instanceclient
 LD_LIBRARY_PATH=/opt/oracle/instanceclient
 ORACLE_BASE=/opt/oracle/instanceclient
 ORACLE_HOME=/opt/oracle/instanceclient
 export DYLD_LIBRARY_PATH LD_LIBRARY_PATH ORACLE_BASE ORACLE_HOME

 (note: As Chris Jones mentioned LD_LIBRARY_PATH is not used on OS X,
 however there is no harm in having it set)

Thanks for your help getting this resolved.

FWIW, I just merged a change to the originally reported Warning:
ocilogon() [function.ocilogon]: OCIEnvNlsCreate() failed.  message.
On Mac OS X this now mentions DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH:
http://cvs.php.net/viewvc.cgi/pecl/oci8/oci8.c?r1=1.269.2.16.2.38.2.31r2=1.269.2.16.2.38.2.32

This fix is incorporated into OCI8 1.3.5 downloadable from
http://pecl.php.net/package/oci8  It will be available with PHP 5.3
(whenever that comes out).  Users of older versions of PHP including
PHP 5.2 are encouraged to upgrade OCI8 using PECL.

Chris

--
Email: christopher.jo...@oracle.com  Tel: +1 650 506 8630
Twitter:  http://twitter.com/ghrdFree PHP Book: http://tinyurl.com/UGPOM

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] SQL for counting comments - is this smart?

2009-03-16 Thread Martin Zvarík

Is it smart to use all of this on one page?
Or should I rather do one SQL and let PHP count it?


$q = $DB-q(SELECT COUNT(*) FROM comments);
$int_total = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved IS NULL);
$int_waiting = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=0);
$int_deleted = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=1);
$int_approved = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=2);
$int_banned = $DB-frow($q);


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] SQL for counting comments - is this smart?

2009-03-16 Thread Chris

Martin Zvarík wrote:

Is it smart to use all of this on one page?
Or should I rather do one SQL and let PHP count it?


$q = $DB-q(SELECT COUNT(*) FROM comments);
$int_total = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved IS NULL);
$int_waiting = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=0);
$int_deleted = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=1);
$int_approved = $DB-frow($q);

$q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=2);
$int_banned = $DB-frow($q);


Each one of these probably going to scan the whole table because the 
approved column isn't going to be selective enough to use an index.


You might be better off doing:

select approved, count(*) from comments group by approved;

then in php separating them out:

while ($row = $DB-frow($q)) {
  switch ($row['approved']) {
 case null:
   $waiting = $row['count'];
 break;
 case 0:
   $deleted = $row['count'];
 break;
 case 1:
   $approved = $row['count'];
 break;
  }
}

$total = $waiting + $approved + $deleted;

--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php