php-general Digest 6 Jul 2008 09:47:13 -0000 Issue 5553
Topics (messages 276321 through 276329):
Re: class_is_loadable?
276321 by: Aschwin Wesselius
276323 by: Eric Butera
Re: odbc msaccess php5
276322 by: Peter Jackson
Re: Trying to keep a dropdown selection sticky
276324 by: Warren Vail
276325 by: Michael S. Dunsavage
276326 by: Michael S. Dunsavage
Re: Asynchronous PHP Execution
276327 by: Waynn Lue
276328 by: Waynn Lue
276329 by: Richard Heyes
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 ---
Pulni4kiya wrote:
Well reimplementing autoloading doesn't seem such a bad idea.
With the integrated autoload ...there is one very stupid way of doing
what you want. Something like this (I suppose you know which class is
the parent of the one that is 'missing'):
eval("class $class_name extends THE_PARENT {}");
You can put a field with the actual class name and fill it in the
constructor so you would know if it's the actual class B or just A
with a different name.
(What I just wrote looks very stupid... Don't laugh at me very much
please. :D)
I'll think of something smarter...this is the first thing that came
into my mind.
Btw why is it so important to use autoloading anyway?
Hi,
Has anybody used the PECL extension automap yet and if so, are there
issues with using that to autoload or not?
Greetings,
Aschwin Wesselius
--- End Message ---
--- Begin Message ---
On Sat, Jul 5, 2008 at 1:36 PM, Larry Garfield <[EMAIL PROTECTED]> wrote:
> Greetings, all.
>
> I am trying to figure out a way to implement the following logic, but I am not
> sure if it is possible to do so without a lot of additional side work:
>
> I have a class, A, and another class B that extends A. They live in separate
> files. The logic I need to implement is as follows:
>
> if (class_exists('B')) {
> $foo = new B();
> }
> else {
> $foo = new A();
> }
>
> That is all well and good if both A and B are already loaded and parsed, but I
> am using spl_autoload to lazy-load classes as needed. That means the
> class_exists() call will return false if B exists but hasn't been included
> yet. What I would like to happen is for PHP to include B if it exists or
> give a non-fatal error if it doesn't so that I can instantiate A instead.
>
> Ideally, the logic would be something like the following:
>
> try {
> $foo = new B(); // Try to autoload B, throw exception if it can't.
> }
> catch (ClassDoesntExistEvenAfterRunningThroughAutoloadException $e) {
> $foo = new A(); // May autoload A at this point, too.
> }
> // do stuff with $foo
>
> However, as far as I am aware $foo = new B(); will cause a fatal exception if
> autoload doesn't find a B.
>
> Does anyone know of a way to achieve the above effect? This is specifically
> for PHP 5.2 and later. Thanks.
>
> --
> Larry Garfield
> [EMAIL PROTECTED]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Perhaps this might do it:
spl_autoload_call('someclass');
if (!class_exists('someclass', false)) { load class A }
--- End Message ---
--- Begin Message ---
Bastien Koert wrote:
On Sat, Jul 5, 2008 at 11:04 AM, Bastien Koert <[EMAIL PROTECTED]> wrote:
On Sat, Jul 5, 2008 at 6:51 AM, Peter Jackson <[EMAIL PROTECTED]>
wrote:
$conn=odbc_connect("Database","",""); works
$a = "abcd"; (this value exists in db)
$stat = "Select * FROM " . '"Table Name"';
$qry = odbc_exec($conn,$stat);
$res = odbc_result_all($qry) or die("Error: ");
The above works as I expect it to.(Returns 70 rows)
If I now want to add a where clause
$stat = "SELECT * FROM " . '"Table Name"' . " Where " . '"Column Name" =
" . $a; (This works)
Now the place I fall into the abyss.
if I change WHERE clause in $stat to
" WHERE " . '"Column Name"' LIKE abc* (or other variations like abc%
"abc%" "abc*" 'abc%' 'abc*')
All I end up with is a blank page or Warning odbc_result_all No tuples
available at this result index.
Also I'm having trouble working out how to use a date in the WHERE clause.
I've tried #yy-mm-dd# yy-mm-dd* dd/mm/yy etc etc (oh and yy/mm/dd 00:00:00
etc
I realize this is probably more odbc/sql related but after a lot of
goggling and reading I havent found the answer (about 5 days so far)
As the data seems to be text based, you need to quote it
WHERE " . '"Column Name"' LIKE 'abc%'
--
Bastien
Cat, the other other white meat
sorry, missed the access dates...
try mm/dd/yyyy as the format
Unfortunately thats the first thing I thought of. I've tried every
variation of quote I could think of. Can anyone tell me how to log what
the odbc connection is actually sending/receiving? (as opposed to
just echoing the sql statement I 'think' its sending.
--- End Message ---
--- Begin Message ---
The selection will stick until you do a form submit. The most common
practice in PHP is to update the database with the value from the form or at
least save it in a session. After the update you can redisplay your form
after fetching the DB contents or getting the selection from the session
into a variable (say $choice) and modify the loop below in your form so that
the echo inside the loop is broken into the following;
foreach ($state_list as $key => $value) {
echo "<option value=\"$key\"";
if($key == $choice) echo " selected"; // now it's sticky
;-)
echo "> $value</option>\n";
}
When you fail to indicate which item in a select list is "selected" most
browsers will default to showing the first entry (effectively unsticking
your choice).
Good luck,
Warren Vail
> -----Original Message-----
> From: Michael S. Dunsavage [mailto:[EMAIL PROTECTED]
> Sent: Friday, July 04, 2008 6:32 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Trying to keep a dropdown selection sticky
>
> I have a form I want to keep sticky, but I can't figure out
> how. I got all the <INPUT>'s to be sticky....
>
> The select script
>
>
> <?php
> echo '<strong>State</strong><br>';
> echo '<select name="State">';
> foreach ($state_list as $key => $value) {
> echo "<option value=\"$key\"> $value</option>\n";
> }
> echo '</select>';
> echo '<br>';
>
>
>
> ?>
>
>
> so now how do I keep that sticky?
>
> --
> Michael S. Dunsavage
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
On Sat, 2008-07-05 at 21:27 -0700, Warren Vail wrote:
> When you fail to indicate which item in a select list is "selected"
> most
> browsers will default to showing the first entry (effectively
> unsticking
> your choice).
>
> Good luck
ahhh! I was wondering where the "selected" came fro :)
Thanx for the explanation.
--
Michael S. Dunsavage
--- End Message ---
--- Begin Message ---
On Sat, 2008-07-05 at 21:27 -0700, Warren Vail wrote:
> foreach ($state_list as $key => $value) {
> echo "<option value=\"$key\"";
> if($key == $choice) echo " selected"; // now it's
> sticky
> ;-)
> echo "> $value</option>\n";
> }
Just another quick ?..
where is $choice coming from?
or is that the name of the select in <SELECT NAME='namehere'>
--
Michael S. Dunsavage
--- End Message ---
--- Begin Message ---
>
> > and exec/shell (but that
>
>> doesn't seem to be asynchronous), but neither seems optimal.
>>
>
> It can be if you redirect the output streams and put an ampersand after it:
>
> <?php
> exec('sleep 5 > /dev/null 2>/dev/null &');
> echo 'Script ended';
> ?>
>
> This tiny sample should end immediately, and the sleep command should run
> on regardless.
>
> Thanks so much for the suggestion, that's what I ended up doing and it
worked, after some fiddling. Just as a side note, does it execute from the
current directory of the file? Previously, I tried calling exec('php
scripts/foo.php'), but it seemed like there was some weird interaction
between different required files. E.g., this was the layout:
orig.php
scripts/foo.php
incl.php
orig.php had the exec line, and foo.php had require_once(../incl.php). But
it seemed like the exec call caused foo.php to execute from the scripts
directory while the require_once caused incl.php to also execute from the
scripts directory.
How does php determine what the working directory is?
--- End Message ---
--- Begin Message ---
On Sat, Jul 5, 2008 at 12:28 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Sat, Jul 5, 2008 at 6:01 AM, Waynn Lue <[EMAIL PROTECTED]> wrote:
> > I have a system where a user clicks on a button which causes rows to
> > be inserted in to the database. I'd also like to run some lengthier
> > post-processing on those rows, but don't want to put it in the
> > critical path of the rows being inserted and returning to the user.
> > What's the best way to either batch up these other actions, or pass
> > them to a thread or other asynchronous process to do the second part
> > of the action?
>
> Can you just run this via a cron or Scheduled Task? Just have a
> boolean column that distinguishes new rows as unprocessed, and flip
> the flag when the cron script processes the row.
>
The problem with that is it requires another column to a table, which across
all our databases will take a really long time. The other way is to create
another table, which means we're inserting across multiple tables.
Waynn
--- End Message ---
--- Begin Message ---
Waynn Lue wrote:
and exec/shell (but that
doesn't seem to be asynchronous), but neither seems optimal.
It can be if you redirect the output streams and put an ampersand after it:
<?php
exec('sleep 5 > /dev/null 2>/dev/null &');
echo 'Script ended';
?>
This tiny sample should end immediately, and the sleep command should run
on regardless.
Thanks so much for the suggestion, that's what I ended up doing and it
worked, after some fiddling. Just as a side note, does it execute from the
current directory of the file?
I think so.
Previously, I tried calling exec('php
scripts/foo.php'), but it seemed like there was some weird interaction
between different required files. E.g., this was the layout:
orig.php
scripts/foo.php
incl.php
orig.php had the exec line, and foo.php had require_once(../incl.php). But
it seemed like the exec call caused foo.php to execute from the scripts
directory while the require_once caused incl.php to also execute from the
scripts directory.
How does php determine what the working directory is?
I believe it's the directory of the original script. So if you had:
require_once('scripts/foo.php');
...in orig.php, that would be correct.
--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
--- End Message ---