php-general Digest 19 Jul 2006 12:54:43 -0000 Issue 4247
Topics (messages 239553 through 239569):
Re: pg_query and COPY in transaction
239553 by: Luis Magaña
239554 by: Jochem Maas
239564 by: Chris
Different php.ini files for different apache processes on one server
239555 by: spam.pflaesterer.de> (Karl Pflästerer)
239556 by: Jochem Maas
239560 by: Michael B Allen
User defined function problem
239557 by: Stephen Lake
239558 by: Jon Anderson
239559 by: Jon Anderson
239561 by: Stephen Lake
239562 by: Jochem Maas
239569 by: Stephen Lake
Re: Name in HTML input
239563 by: Ligaya Turmelle
forcing a script to run on page unload
239565 by: jekillen
239566 by: Paul Scott
PHP Love Letter
239567 by: Martin Alterisio
239568 by: Ligaya Turmelle
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
It is a PHP question because the Postgres querys do work, I ran them
directly on the postgres server and there is no problem, but if you use
pg_query then it does not work, and pg_query is a PHP function, is it no t?
Any way, I've tried already giving each query in separate function
calls, and it does not work either. As the rollback you suggest, I
haven't tried that since it is suppoused to be automatic. So I will try
that and it might work but that does not change the fact that the
pg_query function is not doing what the manual says it should do, or at
least does not beheave as expected.
thank you very much for your help.
regards.
Jochem Maas wrote:
> Luis Magaña wrote:
>> I have the following code:
>>
>> pg_query($conn,"BEGIN TRANSACTION;
>> DELETE FROM codigo_postal;
>> COPY
>> codigo_postal(codigo_postal,asentamiento,tipo_asentamiento,municipio,estado)
>> FROM '$tmpfname2' DELIMITER '|';
>> COMMIT");
>>
>> It is suppoused as I understand it, that if an error occurs on the copy
>> statement, then the codigo_postal table should still have all of the
>> previous records. Actually I've tested it within psql and it works as
>> expected.
>>
>> However, the shown code does not. If an error occurs on the copy
>> transaction, the data on the table gets deleted.
>
> wrapping an SQL question in a php function doesn't make it a php question. ;-)
>
> $apps = array("apache", "mysql", "windows"); $i = 0;
> while ($i++ < 100) printf("how do I install %s?\n", $apps[ rand(0,2) ]);
>
> // I ran that code for a laugh a number of times - seems to a bias towards
> // asking how to install windows... go figure on a php list.
>
>> I'm certainly lost on this one, is it a bug ?, am I doing something
>> wrong ? (most likely I guess)
>
> you are wrong. there is no ROLLBACK specified. I suggest you
> do the queries one by one (i.e. one call to pg_query() for each statement)
> and if the 'COPY' fails call a 'ROLLBACK'
>
> disclaimer: I know nothing about PG as such - I mostly use Firebird;
>
>> Any help will be apprecciated.
>>
>> PHP: 5.1.2
>> PostgreSQL: 8.1.4
>> Apache: 2.0.55
>> Debian Linux with Kernel 2.6.16
>>
>>
>
--
Luis Magaña
Gnovus Networks & Software
www.gnovus.com
--- End Message ---
--- Begin Message ---
Luis Magaña wrote:
> It is a PHP question because the Postgres querys do work, I ran them
> directly on the postgres server and there is no problem, but if you use
> pg_query then it does not work, and pg_query is a PHP function, is it no t?
>
> Any way, I've tried already giving each query in separate function
> calls, and it does not work either. As the rollback you suggest, I
> haven't tried that since it is suppoused to be automatic. So I will try
> that and it might work but that does not change the fact that the
> pg_query function is not doing what the manual says it should do, or at
> least does not beheave as expected.
so it seems that you _may_ have a bug. what version of php are you using?
and do pg_last_error() and/or pg_last_notice() offer any useful info?
(having read the pg_*() docs somewhat I can only - ouch! makes firebird
look even simpler than it is already)
I don't know what the COPY syntax in your SQL does exactly but have you looked
at pg_copy_from() and pg_copy_to() ?
>
> thank you very much for your help.
>
> regards.
>
> Jochem Maas wrote:
>> Luis Magaña wrote:
>>> I have the following code:
>>>
>>> pg_query($conn,"BEGIN TRANSACTION;
>>> DELETE FROM codigo_postal;
>>> COPY
>>> codigo_postal(codigo_postal,asentamiento,tipo_asentamiento,municipio,estado)
>>> FROM '$tmpfname2' DELIMITER '|';
>>> COMMIT");
>>>
>>> It is suppoused as I understand it, that if an error occurs on the copy
>>> statement, then the codigo_postal table should still have all of the
>>> previous records. Actually I've tested it within psql and it works as
>>> expected.
>>>
>>> However, the shown code does not. If an error occurs on the copy
>>> transaction, the data on the table gets deleted.
>> wrapping an SQL question in a php function doesn't make it a php question.
>> ;-)
>>
>> $apps = array("apache", "mysql", "windows"); $i = 0;
>> while ($i++ < 100) printf("how do I install %s?\n", $apps[ rand(0,2) ]);
>>
>> // I ran that code for a laugh a number of times - seems to a bias towards
>> // asking how to install windows... go figure on a php list.
>>
>>> I'm certainly lost on this one, is it a bug ?, am I doing something
>>> wrong ? (most likely I guess)
>> you are wrong. there is no ROLLBACK specified. I suggest you
>> do the queries one by one (i.e. one call to pg_query() for each statement)
>> and if the 'COPY' fails call a 'ROLLBACK'
>>
>> disclaimer: I know nothing about PG as such - I mostly use Firebird;
>>
>>> Any help will be apprecciated.
>>>
>>> PHP: 5.1.2
>>> PostgreSQL: 8.1.4
>>> Apache: 2.0.55
>>> Debian Linux with Kernel 2.6.16
>>>
>>>
>
--- End Message ---
--- Begin Message ---
Luis Magaña wrote:
I have the following code:
pg_query($conn,"BEGIN TRANSACTION;
DELETE FROM codigo_postal;
COPY
codigo_postal(codigo_postal,asentamiento,tipo_asentamiento,municipio,estado)
FROM '$tmpfname2' DELIMITER '|';
COMMIT");
Separate them out as a first step:
$result = pg_query("begin");
if (!$result) {
echo "error at line " . __LINE__ . ": " . pg_last_error() . "<br/>";
}
$result = pg_query("delete from codigo_postal;");
if (!$result) {
echo "error at line " . __LINE__ . ": " . pg_last_error() . "<br/>";
}
$result = pg_query("COPY
codigo_postal(codigo_postal,asentamiento,tipo_asentamiento,municipio,estado)
FROM '$tmpfname2' DELIMITER '|';");
if (!$result) {
echo "error at line " . __LINE__ . ": " . pg_last_error() . "<br/>";
}
$result = pg_query("commit");
if (!$result) {
echo "error at line " . __LINE__ . ": " . pg_last_error() . "<br/>";
}
and see if you get any errors.
--
Postgresql & php tutorials
http://www.designmagick.com/
--- End Message ---
--- Begin Message ---
Hi,
suppose you had several directories a, b and c where in each directory
you had an Apache http.conf file. For each directory Apache gets started
with the http.conf (and other conf files) in that directory.
PHP is used a an Apache module. How can I have a different php.ini file
for each different Apache process (a, b and c)? (Apache is 1.3.33 IIRC)
KP
--- End Message ---
--- Begin Message ---
(Karl Pflästerer) wrote:
> Hi,
> suppose you had several directories a, b and c where in each directory
> you had an Apache http.conf file. For each directory Apache gets started
> with the http.conf (and other conf files) in that directory.
>
> PHP is used a an Apache module. How can I have a different php.ini file
> for each different Apache process (a, b and c)? (Apache is 1.3.33 IIRC)
>
probably your only recourse is too compile 3 different php modules (with
different
php.ini paths).
I heard that there was an apache directive to allow you to specify the location
of php.ini but I know nothing about it and it's possible that it's an apache2
only
thing.
can't think of any other way of doing what you want.
>
>
> KP
>
--- End Message ---
--- Begin Message ---
On Tue, 18 Jul 2006 20:44:35 +0200
<[EMAIL PROTECTED]>(Karl Pflästerer) wrote:
> Hi,
> suppose you had several directories a, b and c where in each directory
> you had an Apache http.conf file. For each directory Apache gets started
> with the http.conf (and other conf files) in that directory.
>
> PHP is used a an Apache module. How can I have a different php.ini file
> for each different Apache process (a, b and c)? (Apache is 1.3.33 IIRC)
You could chroot each apache instance but I would probably try to modify
the apache module to accept a parameter (and in the process verify that
one does not already exist).
Mike
--
Michael B Allen
PHP Extension for SSO w/ Windows Group Authorization
http://www.ioplex.com/
--- End Message ---
--- Begin Message ---
Hey Guys and Gals,
I am having a small problem with a user defined function, I placed it in a
config file and it works as expected, but the problem seems to arise only
when I try to use my login script for a members area I am redeveloping.
The error message that comes up is the following:
Fatal error: Cannot redeclare clean_sql() (previously declared in
C:\Apache2\htdocs\braille\config.php:94) in
C:\Apache2\htdocs\braille\config.php on line 108
The problem is its claiming that I am trying to redeclare the function in
the config file when there is only the original function.
I checked in other area's where this config file is being used and I do not
get this error. Nor am I including other files that have the config included
in them.
The problem is only in my login script. If anyone can give me a little
insight into this error I would be greatly appreciated.
Best Regards,
Steve
--- End Message ---
--- Begin Message ---
This would be the simplest work-around I can think of.
In your config script, wrap an if around your function call:
if (!function_exists('clean_sql')) {
function clean_sql() {
...
}
}
jon
Stephen Lake wrote:
Hey Guys and Gals,
I am having a small problem with a user defined function, I placed it in a
config file and it works as expected, but the problem seems to arise only
when I try to use my login script for a members area I am redeveloping.
The error message that comes up is the following:
Fatal error: Cannot redeclare clean_sql() (previously declared in
C:\Apache2\htdocs\braille\config.php:94) in
C:\Apache2\htdocs\braille\config.php on line 108
The problem is its claiming that I am trying to redeclare the function in
the config file when there is only the original function.
I checked in other area's where this config file is being used and I do not
get this error. Nor am I including other files that have the config included
in them.
The problem is only in my login script. If anyone can give me a little
insight into this error I would be greatly appreciated.
Best Regards,
Steve
--- End Message ---
--- Begin Message ---
Oh, and the other obvious thing that I omitted would be to try using
either the include_once() and require_once() functions wherever you
include() or require() config.php.
jon
Stephen Lake wrote:
Hey Guys and Gals,
I am having a small problem with a user defined function, I placed it in a
config file and it works as expected, but the problem seems to arise only
when I try to use my login script for a members area I am redeveloping.
The error message that comes up is the following:
Fatal error: Cannot redeclare clean_sql() (previously declared in
C:\Apache2\htdocs\braille\config.php:94) in
C:\Apache2\htdocs\braille\config.php on line 108
The problem is its claiming that I am trying to redeclare the function in
the config file when there is only the original function.
I checked in other area's where this config file is being used and I do not
get this error. Nor am I including other files that have the config included
in them.
The problem is only in my login script. If anyone can give me a little
insight into this error I would be greatly appreciated.
Best Regards,
Steve
--- End Message ---
--- Begin Message ---
Thanks Jon,
That did the trick nicely, not sure why I didn't think of it myself but is
glad for the reminder of what that function is for. :)
Best Regards,
Steve
"Jon Anderson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> This would be the simplest work-around I can think of.
>
> In your config script, wrap an if around your function call:
>
> if (!function_exists('clean_sql')) {
> function clean_sql() {
> ...
> }
> }
>
> jon
>
> Stephen Lake wrote:
>> Hey Guys and Gals,
>>
>> I am having a small problem with a user defined function, I placed it in
>> a config file and it works as expected, but the problem seems to arise
>> only when I try to use my login script for a members area I am
>> redeveloping.
>>
>> The error message that comes up is the following:
>>
>> Fatal error: Cannot redeclare clean_sql() (previously declared in
>> C:\Apache2\htdocs\braille\config.php:94) in
>> C:\Apache2\htdocs\braille\config.php on line 108
>>
>> The problem is its claiming that I am trying to redeclare the function in
>> the config file when there is only the original function.
>>
>> I checked in other area's where this config file is being used and I do
>> not get this error. Nor am I including other files that have the config
>> included in them.
>>
>> The problem is only in my login script. If anyone can give me a little
>> insight into this error I would be greatly appreciated.
>>
>> Best Regards,
>> Steve
>>
--- End Message ---
--- Begin Message ---
what Jon said.
but note it's better to stick your functions into a seperate 'funcs' file
and include_once() or require_once() that instead. at some stage you'll have so
many functions you may want to split them up into seperate 'funcs' files
depending
on what they do (and/or what they are used for) but for now start by creating a
a single utility file that just contains functions you have written.
Stephen Lake wrote:
> Hey Guys and Gals,
>
> I am having a small problem with a user defined function, I placed it in a
> config file and it works as expected, but the problem seems to arise only
> when I try to use my login script for a members area I am redeveloping.
>
> The error message that comes up is the following:
>
> Fatal error: Cannot redeclare clean_sql() (previously declared in
> C:\Apache2\htdocs\braille\config.php:94) in
> C:\Apache2\htdocs\braille\config.php on line 108
>
> The problem is its claiming that I am trying to redeclare the function in
> the config file when there is only the original function.
>
> I checked in other area's where this config file is being used and I do not
> get this error. Nor am I including other files that have the config included
> in them.
>
> The problem is only in my login script. If anyone can give me a little
> insight into this error I would be greatly appreciated.
>
> Best Regards,
> Steve
>
--- End Message ---
--- Begin Message ---
Thanx Jon and Jochem for the reminders, they were much appreciated. :)
Best Regards,
Steve
""Stephen Lake"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hey Guys and Gals,
>
> I am having a small problem with a user defined function, I placed it in a
> config file and it works as expected, but the problem seems to arise only
> when I try to use my login script for a members area I am redeveloping.
>
> The error message that comes up is the following:
>
> Fatal error: Cannot redeclare clean_sql() (previously declared in
> C:\Apache2\htdocs\braille\config.php:94) in
> C:\Apache2\htdocs\braille\config.php on line 108
>
> The problem is its claiming that I am trying to redeclare the function in
> the config file when there is only the original function.
>
> I checked in other area's where this config file is being used and I do
> not get this error. Nor am I including other files that have the config
> included in them.
>
> The problem is only in my login script. If anyone can give me a little
> insight into this error I would be greatly appreciated.
>
> Best Regards,
> Steve
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
[snip]
Thanks for your info.
I am new in PHP , how to remove the the space and '(',')' ?
[/snip]
Use the delete key.
LOL
--
life is a game... so have fun.
--- End Message ---
--- Begin Message ---
Hi:
I have a web application that creates files and directories to save info
for a user. If the user decides to link to another page or site
altogether
I want to run a script that will clean up after him or her but won't
interfere with where they are going. It will eventually expand
to asking the user if he or she wants to save the info for a return
visit. If they don't want to save it has to clean up after them
and if they do it goes through the process of tagging and
saving the info on the server.
My strategy is to run a spontaneous form submission with the
body onunload event. Then run the script and exit. I seem to
remember a way to force a script to run and I've seen that
in a site that I visit occasionally. Even if I quit the browser
it still manages to delay the exit of the browser. But I don't
remember whether it was one of my books on php or the php
manual that this is in.
Can someone point me in the right direction?
Thanks in advance:
JK
--- End Message ---
--- Begin Message ---
On Tue, 2006-07-18 at 21:32 -0700, jekillen wrote:
> in a site that I visit occasionally. Even if I quit the browser
> it still manages to delay the exit of the browser. But I don't
> remember whether it was one of my books on php or the php
> manual that this is in.
> Can someone point me in the right direction?
I think you are looking for something like this little class that I
wrote a while back:
http://www.phpclasses.org/browse/package/2837.html
It lets you close the browser and even log off completely, and will send
you an email once the process is done. I use it for a few things, large
PDF generation, importing _very_ large documents into our CMS, cleaning
up user garbage etc.
Take a look and see if it suits your needs. Let me know if you need some
help getting it going as well.
HTH
--Paul
All Email originating from UWC is covered by disclaimer
http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm
--- End Message ---
--- Begin Message ---
Been quiet too much...
*This time, I seriously advise against running this piece of code unless you
know what you're doing*
Enjoy...
-------
<html>
<head>
<title>Love Letter</title>
</head>
<body>
<?php
if (in_array($me, $her->acquaintances)) {
?>
<p>Dear <?=$her->name?>,</p>
<p>I really enjoy your company and I would love to meet you again.</p>
<p>I had a lot of fun last time and I can't wait to get to know you
better.</p>
<p>Yours sincerely, <?=$me->name?></p>
<?php
} else if (in_array($me, $her->intimateFriends)) {
?>
<p>Dear <?=$her->nickName?>,</p>
<p>All I wanted to say is how lucky I'm to have met you, to have you by my
side.</p>
<p>I can't think of a world without you. I can't possibly thank you enough
for all the happy moments you gave me.</p>
<p>Yours, <?=$me->nickName</p>
<?php
} else if (isset($her->boyfriend) && $her->boyfriend == $me) {
$loversNicknames = array('Honey', 'Sweetie', 'Baby', 'Princess',
'Queen', 'Love', 'Sunshine');
?>
<p>My <?=$loversNicknames[array_rand($loversNicknames)]?>,</p>
<p>I couldn't wait to tell you how much I love you.</p>
<p>You're the only one, the reason why I'm on this world. The only place I
wanna be is besides you.</p>
<p>Missing you already, your Love</p>
<?php
} else if (isset($her->husband) && $her->husband== $me) {
?>
<p>I love you.</p>
<p>PS: What's for dinner?</p>
<?php
} else {
// You don't need the love letter, you need a girl
exec('mv '.__FILE__.' > /dev/null');
// Now, get your lazy ass out there
exit;
}
?>
</body>
</html>
--- End Message ---
--- Begin Message ---
Martin Alterisio wrote:
Been quiet too much...
*This time, I seriously advise against running this piece of code unless
you
know what you're doing*
Enjoy...
-------
<html>
<head>
<title>Love Letter</title>
</head>
<body>
<?php
if (in_array($me, $her->acquaintances)) {
?>
<p>Dear <?=$her->name?>,</p>
<p>I really enjoy your company and I would love to meet you again.</p>
<p>I had a lot of fun last time and I can't wait to get to know you
better.</p>
<p>Yours sincerely, <?=$me->name?></p>
<?php
} else if (in_array($me, $her->intimateFriends)) {
?>
<p>Dear <?=$her->nickName?>,</p>
<p>All I wanted to say is how lucky I'm to have met you, to have you by my
side.</p>
<p>I can't think of a world without you. I can't possibly thank you enough
for all the happy moments you gave me.</p>
<p>Yours, <?=$me->nickName</p>
<?php
} else if (isset($her->boyfriend) && $her->boyfriend == $me) {
$loversNicknames = array('Honey', 'Sweetie', 'Baby', 'Princess',
'Queen', 'Love', 'Sunshine');
?>
<p>My <?=$loversNicknames[array_rand($loversNicknames)]?>,</p>
<p>I couldn't wait to tell you how much I love you.</p>
<p>You're the only one, the reason why I'm on this world. The only place I
wanna be is besides you.</p>
<p>Missing you already, your Love</p>
<?php
} else if (isset($her->husband) && $her->husband== $me) {
?>
<p>I love you.</p>
<p>PS: What's for dinner?</p>
<?php
} else {
// You don't need the love letter, you need a girl
exec('mv '.__FILE__.' > /dev/null');
// Now, get your lazy ass out there
exit;
}
?>
</body>
</html>
Finally get to the heart of the matter with the PS... LOL
Nice work - but if I ever found out my husband used a program that ran
on cron to send me a love letter - I would be both impressed (that he
coded it since he doesn't code) and by the 3rd one waiting for flowers
as well.
--
life is a game... so have fun.
--- End Message ---