Re: [PHP-DB] PHP and OCI NLS behaviour

2002-04-16 Thread Graeme Merrall



Rouvas Stathis wrote:
 Hi,
 
 place appropriate NLS_LANG definitions in the Apache startup script
 (/etc/rc.d/apache ?).

As a background to this, it's essential to do this because certain 
things happen when the module is initialised in PHP. Hence if you use 
putenv() to alter some Oracle defaults, it may well be too late because 
that option has already been set then the module was loaded (i.e. when 
Apache starts).

Cheers,
  Graeme


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




RE: [PHP-DB] Help -- Oracle

2002-01-24 Thread Graeme Merrall


 Help, i'm trying to connect to a remote oracle database from
 win98/apache/php4 and win2k/iis/php4 but it always gives me tns
 error. Other
 apps however, works fine with the tns configuration. the php oracle module
 was loaded successfully on both platforms.
 I've tried all sorts of possibilities. path to tnsnames.ora is correct.
 I've even tried with ODBC but when i used it with php, i get
 server refused
 connection. However, ODBC test was successfull and other apps
 can work with
 it.

Can you give us the exact error message?

Cheers,
 Graeme


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Oracle Oci*Logon

2001-08-21 Thread Graeme Merrall

Quoting Andrey Hristov [EMAIL PROTECTED]:

  Can someone tell more about OciPLogon.

I'm sure Theis will add to this but here goes... :)

 I know that OciLogon is used frequently but the connection to the DB
 is
 shared amongst the pages so as in the common way where every page in a
 site
 uses one pair user/password use the only channel. When one script
 makes
 commit it commits all, so if two scripts subsequently made insert but
 one
 thinks that there was a fail it will issue rollback. The problem is
 that
 the other script issued commit and rollback does nothing.
 Someone can tell that the decision is using OciNLogon - ok but I know
 that
 this is the most time consuming way to connect to Oracle.
 The refined question is: Does OciPlogon is like OciLogon - one channel,
 one
 scripts commits/rollbacks all statements, or it is like OciNLogon but
 the
 connection is not made everytime a scripts want such but used already
 created one?.

Oracle connections work across 3 levels, the server, the session and the 
service. AFAIK, transactions work at the service level which is the 'top' 
level. Persistent connections operate at the session level. Tus a persistent 
connection is maintained across Apache children by keeping the bottom level or 
server context open.

We did run into problems because we have very high traffic sites and we have 
100 Apache children running. Because our junior programmer decided to hammer 
the server with a web stress tool, al the  children ran up connections which 
combined with connections on other web server made us run out of sessions.  
Dropping back to icologon() for a while helped the problem.

Anyway, to answer your question, persistent logins will not affect 
transactions  across processes as far as I'm aware. There may be some 
locking/isolations issues if a simultaneous read/write occurs but Oracle should 
handle that anyway.

ocinlogon() is used to guarantee an isolated connection which will not affect 
any outstanding transactions. You only usually do this when you want to do a 
seperate set of operations in the middle of a transaction in a script.

 One more question : When PHP and Oracle works on one machine to make
 all
 work the enviroment variable ORACLE_HOME has to be set for example :
 /***/
 
 // set ORACLE Dir to get the NET8 name resolver working
 // tnsnames.ora has to be in $ORACLE_HOME/networking/admin/
 putenv(ORACLE_HOME=/home/oracle01/app/oracle/product/8.1.5);
 

This is bad. As Theis has pointed out proviously, PHP modules perform certain 
operations at Apache startup and shutdown as well as script startup and 
shutdown. Setting things like ORACLE_HOME, NLS_LANG and so on in your script 
can cause some problems as some of the module has already been initialised 
before your script executes. You're better off putting this stuff in somewhere 
like the apachectl script.


 /***/
 
 but if my web server is an Apache under windows and the oracle is on
 other
 machine under Linux(RH), what have to be done to make my PHP work with
 the
 DB.

Windows is a slightly different beast. Normally the environment stuff is 
handled in windows and you don't need to setup anything with putenv. Use your 
Net8 Configuration assistant which is part of the Oracle Windows client 
libraries to create the correct TNSNAMES.ORA.

AFAIK (I've never tried not to) you must specify the SID when connecting under 
windows in a PHP script.

Cheers,
 Graeme

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] oracle (oci8) intro

2001-08-19 Thread Graeme Merrall

Quoting Cynic [EMAIL PROTECTED]:

 Hi there,
 
 I'm in a situation where I need to produce a small app
 on top of an Oracle server really quickly. I'm quite a
 seasoned developer, but have only experience with MySQL
 so far. It's my understanding that Oracle lacks the 
 MySQL's LIMIT feature. Looking at the OCI section of 
 the PHP manual, it also looks like there's no 
 OCIDataSeek() or some equivalent. Since the app I need
 to build will be a standard report builder with paging,
 I need this functionality. What is the common way to 
 achieve this? Always fetch all rows, cycling through the
 resultset, discarding the records that preceed the one
 I want to start displaying with, and quit when I reach
 the one where the page should end?
 
 Is there a PHP + OCI tutorial somewhere?
 
 I need an intro to Oracle, and I need it now. :(

Thies has an Oracle/PHP tutorial online at http://conf.php.net/ which may be of 
some assitance. 
The LIMIT problem is a real bitch is Oracle. There are a few ways to get around 
it, the most obvious people use being ROWNUM. However, ROWNUM does not listen 
to sorting which makes life amusing.
One option is to try a query like the following:
SELECT * FROM (SELECT field1, field2 FROM table WHERE id10 ORDER BY field1 
DESC) WHERE ROWNUM11

which gives you 10 rows, but still leaves the question of paging behind unless 
you use between values. I can't say I've tried paging record sets though.

Cheers,
 Graeme

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] OCIDefineByName/OCIBindByName help?

2001-08-13 Thread Graeme Merrall

Quoting Barry Prentiss [EMAIL PROTECTED]:

 Hi,
  Can anyone help me to understand the OCIBindByName/OCIDefineByName
 functionality when used with the Oracle 'returning' clause? These two
 functions are seriously under-documented at PHP.net.
  I need the sequence-generated ID created during an insert for further
 manipulation.
  I tried sequence-name.currval but got an error.
  Here's some code that doesn't work:
 
$sql = insert into mdfaq values (null,'$Question','$Answer')
 returning
 ID into :ID;
$stmt = ociParse($conn,$sql);
OCIBindByName($stmt,:ID,$faq_ID,-1);

You don't need to pass by reference and you should be able to ommit the length 
parameter. You should probably bind $Question and $Answer as well. That way 
your queries will be more efficient and you dont have to worry about escaping 
quotes.

Also your SQL should be 
INSERT INTO mdfaq VALUES (sequence.nextval, '$Question', '$Answer') returning 
ID into :id

ID should be the column name of your primary key column.

ocidefinebyname is useful for pulling columns out of Oracle so you don't need 
to make calls to ociresult() all the time. I actually don't see much benefit 
over using fetchstatement()

Cheers,
 Graeme

Cheers,
 Graeme

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] OCIDefineByName/OCIBindByName help?

2001-08-13 Thread Graeme Merrall

Quoting Barry Prentiss [EMAIL PROTECTED]:

 Hi,
  Can anyone help me to understand the OCIBindByName/OCIDefineByName
 functionality when used with the Oracle 'returning' clause? These two
 functions are seriously under-documented at PHP.net.
  I need the sequence-generated ID created during an insert for further
 manipulation.
  I tried sequence-name.currval but got an error.
  Here's some code that doesn't work:
 
$sql = insert into mdfaq values (null,'$Question','$Answer')
 returning
 ID into :ID;
$stmt = ociParse($conn,$sql);
OCIBindByName($stmt,:ID,$faq_ID,-1);

You don't need to pass by reference and you should be able to ommit the length 
parameter. You should probably bind $Question and $Answer as well. That way 
your queries will be more efficient and you dont have to worry about escaping 
quotes.

Also your SQL should be 
INSERT INTO mdfaq VALUES (sequence.nextval, '$Question', '$Answer') returning 
ID into :id

ID should be the column name of your primary key column.

ocidefinebyname is useful for pulling columns out of Oracle so you don't need 
to make calls to ociresult() all the time. I actually don't see much benefit 
over using fetchstatement()

Cheers,
 Graeme

Cheers,
 Graeme

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] MSSQL: Spaces in database name

2001-08-08 Thread Graeme Merrall

Quoting Robert D. Young [EMAIL PROTECTED]:

 That did it! Using:
 
 ... stuff 
 $dbname = [Test Database]; 
 ... more stuff 
 mssql_select_db($dbname);
 
 worked perfectly. Again, Thanks!

This is standard Microsoft (and maybe ODBC?) syntax. Using square brackets will 
work on most things including table names and field names with spaces in them. 
This will work fine

SELECT [table space].[field space] FROM [table space]

It doesn't mean that you should go around putting spaces in your database 
objects. That's never a good idea :)

Cheers,
 Graeme

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] ORACLE 8 randomly unsucessful execution

2001-06-23 Thread Graeme Merrall

Do you get an Oracle error code back?
What version of PHP are you using?

Cheers,
 Graeme

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf
 Of Ludo
 Sent: Saturday, 23 June 2001 1:31 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] ORACLE 8 randomly unsucessful execution


 Hi!

 We encounter a weird problem here:
 from time to time, after a up-time of one week for instance, the PHP pages
 cannot execute some PL/SQL stored procedures (most of the time it
 works, but
 sometimes it doesn't). We solve the problem by restarting Apache,
 but having
 no idea of where the problem comes from ...

 Any idea?

 Ludo.

 
 Here is ou PHP configure script:
 ./configure \
 --with-oracle=/home/oracle/u01/app/oracle/product/8.1.6 \
 --with-oci8=/home/oracle/u01/app/oracle/product/8.1.6 \
 --with-apache=/usr/local/apache \
 --enable-curl \
 --enable-track-vars \
 --disable-debug \
 --without-gd \
 --without-mysql \
 --enable-sigchild

 And this is our Apache one:
 ./configure \
 --prefix=/usr/local/apache \
 --activate-module=src/modules/php4/libphp4.a \
 --enable-module=rewrite \
 --enable-rule=SHARED_CORE \
 --enable-module=so



 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] RE: Informix user wierdness

2001-04-01 Thread Graeme Merrall


 This is more an Informix question rather than a PHP question but
 I hope someone can help
 I've installed the Linux-SE version and CSDK of Informix from
 informix.com and installation has gone fine including createing
 the demo DB. I can also start 'dbaccess' and browse/query the
 tables so the envvars seem fine.

 However, when I endeavour to use the PHP functions, I get an
 error in ifx_connect()
 I constantly get the error:
 E [SQLSTATE=IX 000 SQLCODE=-952]
 User ()'s password is not correct for the database server.

 Note how the username field is empty. What's the procedure for
 'logging in' to the DB? I created the demo DB as a normal user
 and I've read that the user auth stuff is done through the
 operating system.
 Using 'dbaccess' to try and connect to the DB as the same user
 rather then starting dbaccess in the DB dir causes the same error
 to occur so it's obviously something in the setup.

 My sqlhosts line is 'demo_se seipcpipdev sqlexec'
 and the ifx_connect line is 'ifx_connect("stores7@demo_se",
 "testuser", "mypasswd")'

Answered my own question after taking some time out ;). Here's what I found
for the sake of the archives.

Turns out Informix has some sort of PAM/shadow password problem which means
it won't talk nicely because it tries to auth the user, but because of the
bug it can't get the user and therein lies the problem.
Luckily I'm on a dev box so I was able to run 'pwunconv' to return my passwd
file to a non shadow state which in a production system is 'not a good
thing'(tm)

A search in comp.databases.informix on google/deja on shadow and PAM etc
will reveal the problem. Apparently there are workarounds for this but I
haven't found the, yet. I suspect they will require surgery to something
important :)

Cheers,
 Graeme


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Informix user wierdness

2001-03-31 Thread Graeme Merrall

This is more an Informix question rather than a PHP question but I hope
someone can help
I've installed the Linux-SE version and CSDK of Informix from informix.com
and installation has gone fine including createing the demo DB. I can also
start 'dbaccess' and browse/query the tables so the envvars seem fine.

However, when I endeavour to use the PHP functions, I get an error in
ifx_connect()
I constantly get the error:
E [SQLSTATE=IX 000 SQLCODE=-952]
User ()'s password is not correct for the database server.

Note how the username field is empty. What's the procedure for 'logging in'
to the DB? I created the demo DB as a normal user and I've read that the
user auth stuff is done through the operating system.
Using 'dbaccess' to try and connect to the DB as the same user rather then
starting dbaccess in the DB dir causes the same error to occur so it's
obviously something in the setup.

My sqlhosts line is 'demo_se seipcpipdev sqlexec'
and the ifx_connect line is 'ifx_connect("stores7@demo_se", "testuser",
"mypasswd")'

Cheers,
 Graeme


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] pg_put_line and file()

2001-01-27 Thread Graeme Merrall

Hi.
I was tinkering around with pg_put_line and pg_end_copy and rather than
inserting data from a variable as per the example, I was wondering if it was
posible to insert the data from a delimited file via these two functions.
I produced a dump from postgres and tried inserting the data raw
$text = file("test.sql");
$db = pg_connect("host=localhost dbname=testing user=testing");
pg_exec($db, "COPY test FROM stdin");
foreach($text as $line) {
echo $line, "BR";
pg_put_line($db,$line);
flush();
}
pg_end_copy($db);

but this caused an error to occur. The example in the docs had the new lines
and tabs escaped so I tried that as well with addslashes()

$text = file("test.sql");
$db = pg_connect("host=localhost dbname=graeme user=graeme");
pg_exec($db, "COPY test FROM stdin");
foreach($text as $line) {
$line = addslashes($line);
$line = ereg_replace(9,"\\t",$line);
$line = ereg_replace(10,"\\n",$line);
echo $line, "BR";
pg_put_line($db,$line);
flush();
}
pg_end_copy($db);

and while the data was exactly the same format as the example, I managed to
get postgres stuck in COPY and had to manually kill the postgres COPY
process to recover.
Any one have any ideas?

Cheers,
 Graeme


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]