OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 27 Jan 2007 06:03:54 -0000 Issue 4592

php-general-digest-helplists.php.net
Date: Sat Jan 27 2007 - 00:03:54 CST


php-general Digest 27 Jan 2007 06:03:54 -0000 Issue 4592

Topics (messages 247840 through 247872):

Re: SQL Readability.. (was Re: most powerful php editor)
        247840 by: Jochem Maas
        247841 by: tg-php.gryffyndevelopment.com
        247844 by: Satyam
        247845 by: Robert Cummings
        247846 by: Robert Cummings
        247861 by: Larry Garfield

memory_limit Setting?
        247842 by: Jay Paulson
        247843 by: Jon Anderson
        247848 by: Sancar Saran

Re: Ongoing encoding issues
        247847 by: Roman Neuhauser
        247857 by: Roman Neuhauser

Re: Multi lingual pages
        247849 by: Otto Wyss
        247850 by: Robert Cummings
        247853 by: Paul Novitski
        247869 by: Jochem Maas

PHP with XML database
        247851 by: Ritesh Nadhani
        247859 by: Bernhard Zwischenbrugger
        247868 by: Ritesh Nadhani
        247871 by: Bernhard Zwischenbrugger

Re: php & javascript interaction
        247852 by: Scripter47

Creating an array as a property of an object
        247854 by: Ken Kixmoeller -- reply to ken.kixmoeller.com
        247855 by: Robert Cummings
        247856 by: Ken Kixmoeller -- reply to ken.kixmoeller.com

Result sorting not working
        247858 by: Dan Shirah

Can a class instance a property of another class
        247860 by: Ken Kixmoeller -- reply to ken.kixmoeller.com
        247863 by: Jay Blanchard
        247864 by: Jay Blanchard
        247865 by: Jochem Maas
        247866 by: Roman Neuhauser

PHP & Flash
        247862 by: Skip Evans
        247867 by: Jochem Maas
        247870 by: Skip Evans

Create ACH Origination file with PHP
        247872 by: Dan Harrington

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Jon Anderson wrote:
> This may not be an option for many people, 'cause ISPs and web hosts may
> not be forward-thinking enough to install PDO or recent PHP, but...
>
> PDO can do do this in a very database independant way, without having to
> do the equivalent of "mysql_real_escape_string":
>
> $table = 'xyz';
> $data = array(
> 'Field1' => "Data1",
> 'Field2' => "Data2"
> );
>
> $fields = implode(',',array_keys($data));
> $placeholders = ':' . implode(',:',array_keys($data));
> $stmt = $dbh->prepare("INSERT INTO $table ($fields)
> VALUES($placeholders)");
> $stmt->execute($data);
>
> With the added bonus that you can insert multiple rows quickly without
> having to rebuild any queries...
>
> $stmt->execute($data1);
> $stmt->execute($data2);
> ...
> $stmt->execute($dataN);
>
> (And PDO is super-fast compared to some other similar PHP-based libraries.)

unless your using firebird (http://php.net/ibase), in which case PDO is useless.
not that that matters because the ibase extension does this (and has done this for
longer than PDO has existed) natively (as in the DB engine does the real parameter
related lifting, as opposed to some php extension - no offence to php devs but I'd
rather entrust this to the people who developed the data base engine) and additionally
the ibase extension is much more intuitive when it comes parameterized queries.

$res = ibase_query('INSERT INTO foo (first, last) VALUES (?, ?)', $first, $last);

[no that wasn't very helpful was it :-P]

attached mail follows:


Strangely enough, Stut and Jochem, I DO find this more readable. Hah. I know, I'm insane. I have done it the way you guys proposed, using an associative array and using the keys and values as the columns and insert values. While that is what I'd call "tighter" code and when you understand what it's doing, is just as simple to maintain as how I do it, I do find my method more 'readable'.

I tend to build queries in WinSQL first, then insert them into my PHP code. Some of which are fairly complicated and I find if I keep my PHP code similar to my SQL code, it makes it easier to go back and forth to tweak it. They both have a similar look to me.

So instead of using:

$query = "SELECT BunchOfJoinedColumns";
$query .= " FROM BunchOfJoinedTables";
$query .= " WHERE SomeConditions";
$query .= " AND MoreConditions";

for long complicated SELECT statements, then using the method you guys use for INSERT statements, I'm keeping my code consistant whether it's SELECT, INSERT, UPDATE, whatever.

To me, consistancy wins out in a choice between two (imo) equally easily maintained coding styles.

But hey.. I'm always willing to learn new stuff. One reason I posted this was to see more of what other people did with their code, SQL queries in particular.

Cheers!

-TG

= = = Original message = = =

tg-phpgryffyndevelopment.com wrote:
> My contribution to the insanity.. INSERT statements made easy:
>
> $genericQY = "INSERT INTO MOD_LMGR_Leads ("; $genericQYvalues = " VALUES (";
> $genericQY .= " FirstName,"; $genericQYvalues .= " 'John',";
> $genericQY .= " LastName"; $genericQYvalues .= " 'Smith'";
> $genericQY .= " )"; $genericQYvalues .= " );";
> $genericQY .= $genericQYvalues;
> $genericRS = mysql_query($genericQY);

You call that readable??

$vals = array();
$vals['FirstName'] = 'John';
$vals['LastName'] = 'Smith';
$query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

function BuildInsert($table, $values)

     foreach (array_keys($values) as $key)
         $values[$key] = mysql_real_escape_string($values[$key]);

     $sql = 'insert into `'.$table.'` (`';
     $sql.= implode('`,`', array_keys($values));
     $sql.= '`) values ("';
     $sql.= implode('","', array_values($values));
     $sql.= '")';

     return $sql;

Note that this is a *very* cut down and untested version of BuildInsert.

-Stut

___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

attached mail follows:


----- Original Message -----
From: "Stut" <stuttlegmail.com>
> You call that readable??
>
> $vals = array();
> $vals['FirstName'] = 'John';
> $vals['LastName'] = 'Smith';
> $query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));
>
> function BuildInsert($table, $values)
> {
> foreach (array_keys($values) as $key)
> $values[$key] = mysql_real_escape_string($values[$key]);
>
> $sql = 'insert into `'.$table.'` (`';
> $sql.= implode('`,`', array_keys($values));
> $sql.= '`) values ("';
> $sql.= implode('","', array_values($values));
> $sql.= '")';
>
> return $sql;
> }
>

I use to build SQL statements with a BuildSql function, which you can see
at: http://www.satyam.com.ar/int/BuildSql.php

It is commented in PhpDoc format.

For example:

echo BuildSql('Insert into ?ptable
(?s,?ns,?mi,?d,?ni,?i,?t)','Something','',5,time(),0,null,mktime(3,4,5)-
mktime(0,0,0));

Will return:

Insert into wp_table ('Something',null,5,'2007-01-21 15:54:27',null,0,'0
04:04:05')

It is not only meant to build inserts but it is more like a sort of
SQL-oriented sprintf(), like it does proper handling of null values, such as
avoiding puting the text 'null' (notice the quotes) instead of the value
null. It also has a ?p 'prefix' modifier to use a fixed prefix on all table
names.

As for formatting, I usually put the SQL statement in one line and the
arguments in the next one with spaces to align them vertically, which I
won't show here since the formatting of the message will ruin it anyway.

attached mail follows:


On Fri, 2007-01-26 at 16:30 +0000, Stut wrote:
> tg-phpgryffyndevelopment.com wrote:
> > My contribution to the insanity.. INSERT statements made easy:
> >
> > $genericQY = "INSERT INTO MOD_LMGR_Leads ("; $genericQYvalues = " VALUES (";
> > $genericQY .= " FirstName,"; $genericQYvalues .= " 'John',";
> > $genericQY .= " LastName"; $genericQYvalues .= " 'Smith'";
> > $genericQY .= " )"; $genericQYvalues .= " );";
> > $genericQY .= $genericQYvalues;
> > $genericRS = mysql_query($genericQY);
>
> You call that readable??
>
> $vals = array();
> $vals['FirstName'] = 'John';
> $vals['LastName'] = 'Smith';
> $query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

Geee, you call that readable???

$vals = array
(
    'FirstName' => 'John',
    'LastName' => 'Smith',
);

$query = mysql_query( BuildInsert( 'MOD_LMGR_Leads', $vals ) );

;) ;)

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


On Fri, 2007-01-26 at 12:25 -0500, tg-phpgryffyndevelopment.com wrote:
> Strangely enough, Stut and Jochem, I DO find this more readable. Hah. I know, I'm insane. I have done it the way you guys proposed, using an associative array and using the keys and values as the columns and insert values. While that is what I'd call "tighter" code and when you understand what it's doing, is just as simple to maintain as how I do it, I do find my method more 'readable'.
>
> I tend to build queries in WinSQL first, then insert them into my PHP code. Some of which are fairly complicated and I find if I keep my PHP code similar to my SQL code, it makes it easier to go back and forth to tweak it. They both have a similar look to me.
>
> So instead of using:
>
> $query = "SELECT BunchOfJoinedColumns";
> $query .= " FROM BunchOfJoinedTables";
> $query .= " WHERE SomeConditions";
> $query .= " AND MoreConditions";

> But hey.. I'm always willing to learn new stuff.
> One reason I posted this was to see more of what other
> people did with their code, SQL queries in particular.

My insert style is very similar to my select style:

<?php

$query =
    "INSERT INTO someTable "
   ."( "
   ." field1, "
   ." field1, "
   ." field1 "
   .") "
   ."VALUES "
   ."( "
   ." ".$db->quote( $value1 ).", "
   ." ".$db->quote( $value2 ).", "
   ." ".$db->quote( $value3 )." "
   .") ";

?>

Or if there's a lot of fields:

<?php

$data = array
(
    'field1' => $value1,
    'field2' => $value2,
    'field3' => $value3,
    ...
);

$query =
    "INSERT INTO someTable "
   ."( "
   . implode( ", ", array_keys( $data ) )." "
   .") "
   ."VALUES "
   ."( "
   . implode( ", ", $db->quoteArray( $data ) )." "
   .") ";

?>

Although, I don't find myself doing much in the way of inserts these
days since I often extend a data object class that performs the inserts
and updates as necessary.

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


I have long since given up on raw insert/update/delete statements as the
syntax is all kinds nasty. These days I just do this, which is even easier
and more powerful:

http://www.garfieldtech.com/blog/simplifying-sql

On Friday 26 January 2007 10:03 am, tg-phpgryffyndevelopment.com wrote:
> My contribution to the insanity.. INSERT statements made easy:
>
> $genericQY = "INSERT INTO MOD_LMGR_Leads ("; $genericQYvalues = " VALUES
> ("; $genericQY .= " FirstName,"; $genericQYvalues .= "
> 'John',"; $genericQY .= " LastName"; $genericQYvalues
> .= " 'Smith'"; $genericQY .= " )";
> $genericQYvalues .= " );"; $genericQY .= $genericQYvalues;
> $genericRS = mysql_query($genericQY);
>
>
> I use this structure so if I decide that I don't need certain data I can
> comment out a single line to remove the column name and corresponding
> value. Also helpful for making updates to column/value pairs and not worry
> about the dreaded error involve # of columns not matching.
>
> Only things you have to watch for:
>
> 1. Make sure you don't have a comma on the last item
> 2. Make sure you have spaces where appropriate so when it concatenates the
> strings, you don't get stuff crammed together (not really an issue with the
> INSERT statement, but I try to keep a consistant practice with all my
> queries so I don't slip up.. SELECT columnsFROM tableWHERE something =
> something is where it really gets ya if you forget spaces.. just as an
> example) 3. Make sure to remember to concatenate the "query" and "values"
> parts
>
> I like to think this is a little "outside the box" thinking since common
> practice is "one command, one line" or "total chaos" hah.
>
> Any comments on improving this or other unique stylistic ways people like
> to design their code?
>
> -TG
>
>
> = = = Original message = = =
>
> On Wed, January 24, 2007 8:07 pm, Robert Cummings wrote:
> > On Wed, 2007-01-24 at 18:23 -0600, Richard Lynch wrote:
> >> On Wed, January 24, 2007 7:41 am, Roman Neuhauser wrote:
> >> > # sancar.saranevodot.com / 2007-01-24 13:57:03 +0200:
> >> >> and also in these days I'm looking for 19 inch (or more) wide LCD
> >> >> sceerns to able to fit longer lines in my screen...
> >> >
> >> > Number of reading errors people make grows with line length,
> >> > this has been known for as long as I remember. You're increasing
> >>
> >> the
> >>
> >> > probability of bugs in the code, and get tired sooner because
> >> > following
> >> > long lines requires more energy.
> >>
> >> I believe those results are specific to what is being read.
> >>
> >> Surely it's easier to read:
> >>
> >> SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah
> >>
> >> if it's all on one line, no matter how many fields there are, while
> >> trying to read the code as a whole.
> >>
> >> Sure, it can be "hard" to find/read the individual field names, on
> >> the
> >> rare occasion that you need to do that...
> >
> > Dear Mr Lynch, normally I highly respect your commentary on the list,
> > but today I think you've been-a-smoking the crackpipe a tad too much.
> >
> > There is no way in hell one long line of SQL is easier to read than
> > formatted SQL that clearly delineates the clause structure.
> >
> > SELECT A.field1 AS afield1, A.field2 AS afield2, B.field1 AS bfield1,
> > B.field2 AS bfield2, C.field1 AS cfield1, C.field2 AS cfield2,
> > D.field1
> > AS dfield1, D.field2 AS dfield2 FROM tableA as A LEFT JOIN tableB AS B
> > ON B.fee = A.foo LEFT JOIN tableC AS C ON C.fii = B.fee LEFT JOIN
> > tableD
> > AS D ON D.fuu = C.fii WHERE A.foo = 'someValue' ORDER BY afield1 ASC,
> > cfield2 ASC
> >
> > The above line "should" be on one line, but my email client might
> > autowrap it. Either way, the following is formatted and is much
> > clearer.
> >
> > SELECT
> > A.field1 AS afield1,
> > A.field2 AS afield2,
> > B.field1 AS bfield1,
> > B.field2 AS bfield2,
> > C.field1 AS cfield1,
> > C.field2 AS cfield2,
> > D.field1 AS dfield1,
> > D.field2 AS dfield2
> > FROM
> > tableA as A
> > LEFT JOIN tableB AS B ON
> > B.fee = A.foo
> > LEFT JOIN tableC AS C ON
> > C.fii = B.fee
> > LEFT JOIN tableD AS D ON
> > D.fuu = C.fii
> > WHERE
> > A.foo = 'someValue'
> > ORDER BY
> > afield1 ASC,
> > cfield2 ASC
> >
> >
> > While the above is contrived, most of us know such examples happen
> > quite
> > often in the wild. Not only is it easier to read, but the task of
> > adding
> > or removing selected fields is trivial.
>
> I meant ONLY the SELECT part on a single line.
>
> Only a moron would cram the FROM and all that into the same line.
>
> :-)
>
> $query = "SELECT blah1, blah2, blah3, ... blah147 ";
> $query .= " FROM table1 ";
> $query .= " LEFT OUTER JOIN table2 ";
> $query .= " ON blah7 = blah42 ";
> $query .= " WHERE blah16 ";
> $query .= " AND blah42 ";
> $query .= " ORDER BY blah9, blah8 desc, blah6 ";
>
> is what I go for.
>
> The SELECT line is the only one that ever gets all that long, really...
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some starving artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
> ___________________________________________________________
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.

--
Larry Garfield AIM: LOLG42
larrygarfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson

attached mail follows:


Hi everyone,

I¹m trying to upload a 25MB file via PHP and I¹m setting the memory limit
way high so I don¹t get a fatal error from php (the error is below). What I
find really odd about this is that the error message says that PHP tried to
allocate almost 54MB. First question is why is PHP allocating so much
memory when I¹m only uploading a 25MB file? Second question is why is PHP
failing when obviously the memory limit is set to just over 100MB? (I¹m
using PHP 5.1.2 Apache 2.0.55 and using an .htaccess file to change the PHP
settings on the fly.)

Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to
allocate 53764163 bytes) in /path/to/php/file on line 942

.htaccess settings below:

php_value memory_limit 100M
php_value post_max_size 30M
php_value upload_max_filesize 30M
php_value max_execution_time 300
php_value max_input_time 300
php_value display_errors On

attached mail follows:


Jay Paulson wrote:
> Hi everyone,
>
> I¹m trying to upload a 25MB file via PHP and I¹m setting the memory limit
> way high so I don¹t get a fatal error from php (the error is below). What I
> find really odd about this is that the error message says that PHP tried to
> allocate almost 54MB. First question is why is PHP allocating so much
> memory when I¹m only uploading a 25MB file?
Question is what does your code look like? AFAIK, PHP uploads files to a
temp directory where you can do whatever you want with them. If you
don't read them into memory, it won't use a lot of memory (just the
overhead required for the $_FILES array).
> Second question is why is PHP
> failing when obviously the memory limit is set to just over 100MB?
It's trying to allocate over 50M, but fails because existing memory
usage + attempted memory usage is greater than 100M. Call
memory_get_usage() right before the line on which it fails to see how
much memory is being used by your script.

jon

attached mail follows:


On Friday 26 January 2007 19:35, Jay Paulson wrote:
> Hi everyone,
>
> I¹m trying to upload a 25MB file via PHP and I¹m setting the memory limit
> way high so I don¹t get a fatal error from php (the error is below). What
> I find really odd about this is that the error message says that PHP tried
> to allocate almost 54MB. First question is why is PHP allocating so much
> memory when I¹m only uploading a 25MB file? Second question is why is PHP
> failing when obviously the memory limit is set to just over 100MB? (I¹m
> using PHP 5.1.2 Apache 2.0.55 and using an .htaccess file to change the PHP
> settings on the fly.)
>
>
> Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to
> allocate 53764163 bytes) in /path/to/php/file on line 942
>
> .htaccess settings below:
>
> php_value memory_limit 100M
> php_value post_max_size 30M
> php_value upload_max_filesize 30M
> php_value max_execution_time 300
> php_value max_input_time 300
> php_value display_errors On

In these days combining UTF-8 with serialize commands gives memory problems.
Is your code coantains this combination.

?

attached mail follows:


# buddhamagnetgmail.com / 2007-01-26 09:33:13 +0000:
> Hi all, I posted a question a couple of days ago regarding a web app I have
> wherein users are able to indicated prices and concessions via a text field,
> and the resulting encoding issues I have experienced, the main one being
> seeing the pound sign as Â? if viewing the results in a browser with the
> encoding set to Latin-1.
>
> My question is, how do I overcome this. If I set my browser encoding to
> Latin-1 and enter the data I get that odd symbol, if I set it to UTF-8 I get
> clean data. Is there a way to sniff out what encoding the browser is using
> and then clean the data in any way.
>
> I am googling for help also but you guys have been so helpful in the past I
> thought I'd try you also.

Your PostgreSQL database uses some encoding, your PHP script runs under
some locale (incl. character encoding), and the browser sent the text in
some encoding. PostgreSQL assumes the input data is in the charset the
database uses (unless you have client_encoding set in postgresql.conf, or
PGCLIENTENCODING (IIRC) in the environment, or have set client_encoding
using the SET command).

It's important that you correctly identify encoding of the inserted data
to PostgreSQL or convert it to the encoding it expects beforehand. You
can use iconv or recode functions in PHP, I'd probably have a look if
there's an apache input filter for character encoding conversions.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

attached mail follows:


# neuhausersigpipe.cz / 2007-01-26 21:09:34 +0000:
> # buddhamagnetgmail.com / 2007-01-26 09:33:13 +0000:
> > Hi all, I posted a question a couple of days ago regarding a web app I have
> > wherein users are able to indicated prices and concessions via a text field,
> > and the resulting encoding issues I have experienced, the main one being
> > seeing the pound sign as Â? if viewing the results in a browser with the
> > encoding set to Latin-1.
>
> Your PostgreSQL database uses some encoding,

Dave pointed out to me that he's using MySQL. That means the
configuration mechanisms for the database will be different, but the
principal issue remains the same.

> your PHP script runs under some locale (incl. character encoding), and
> the browser sent the text in some encoding. PostgreSQL assumes the
> input data is in the charset the database uses (unless you have
> client_encoding set in postgresql.conf, or PGCLIENTENCODING (IIRC) in
> the environment, or have set client_encoding using the SET command).
>
> It's important that you correctly identify encoding of the inserted data
> to PostgreSQL or convert it to the encoding it expects beforehand. You
> can use iconv or recode functions in PHP, I'd probably have a look if
> there's an apache input filter for character encoding conversions.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

attached mail follows:


Paul Novitski wrote:

I formulated my question in general since I couldn't find an other
message here about supporting multiple languages.

> http://www.w3.org/International/articles/
>
> http://www.w3.org/TR/i18n-html-tech-lang/
>
> http://php.net/setlocale
>
Thanks a lot, these are good points for reading.
>
> 1) Switching language downloads a new version of the current page,
> generally with the same markup but new text. Example:
> http://partcon.ca/
>
I'll favor this way especially if several languages have to be provided.

> In both cases I store the text in database tables that contain a
> language field I can select on to match the user's request.
>
I wonder if retrieving static texts from the database draws too much
performance. I know from somebody who stores texts in large data arrays
an uses shared memory, yet I haven't figured it out how.

I consider storing static texts as defines and just load a different
definition file when the user switches language. Is this practical?

O. Wyss

attached mail follows:


On Fri, 2007-01-26 at 21:25 +0100, Otto Wyss wrote:
> Paul Novitski wrote:
>
> I formulated my question in general since I couldn't find an other
> message here about supporting multiple languages.
>
> > http://www.w3.org/International/articles/
> >
> > http://www.w3.org/TR/i18n-html-tech-lang/
> >
> > http://php.net/setlocale
> >
> Thanks a lot, these are good points for reading.
> >
> > 1) Switching language downloads a new version of the current page,
> > generally with the same markup but new text. Example:
> > http://partcon.ca/
> >
> I'll favor this way especially if several languages have to be provided.
>
> > In both cases I store the text in database tables that contain a
> > language field I can select on to match the user's request.
> >
> I wonder if retrieving static texts from the database draws too much
> performance. I know from somebody who stores texts in large data arrays
> an uses shared memory, yet I haven't figured it out how.

Sure it does, but you can accumulate all the retrieved texts for a page
and cache them so subsequent hits only require a query for the cached
entries. If the page has some translations that may or may not show up
depending on certain values, then you can retrieve the cache, update the
cache with each translation not previously cached and then re-store the
cache. After a while you'll only make 1 query (2 if you're sloppy and
don't check a dirty bit for if the cache actually changed :)

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


At 1/26/2007 12:25 PM, Otto Wyss wrote:
>Paul Novitski wrote:
>>In both cases I store the text in database tables that contain a
>>language field I can select on to match the user's request.
>
>I wonder if retrieving static texts from the database draws too much
>performance. I know from somebody who stores texts in large data
>arrays an uses shared memory, yet I haven't figured it out how.
>
>I consider storing static texts as defines and just load a different
>definition file when the user switches language. Is this practical?

If you store your text in a data table and retrieve it with a query,
you're leaning your weight on SQL (or your database engine of choice).

If you store your text in individual text files, you're leaning on
the operating system's own database system to locate, open, and read the file.

If you store all your text in a single text file, you're leaning on
server memory to store everything when you may only want a few chunks.

Unless your site is insanely popular or huge, does the method really
matter so much? The idea of storing all the text for an entire
website in a single text file sounds scary but feasible if the site
size is modest. Servers and database engines are built to perform
file I/O quickly & efficiently, and I find it unlikely that you'll
strain the system unless your traffic is enormous, your content huge,
and your queries inefficient.

Is your "static text" really static? How often is it modified? If
you're really concerned about streamlining, consider building your
pages dynamically from a database but then caching them on the server
as plain html, refreshing individual files in the cache when your
SQL-based content changes.

Regards,

Paul
__________________________

Juniper Webcraft Ltd.
http://juniperwebcraft.com

attached mail follows:


Otto Wyss wrote:
> Paul Novitski wrote:
>
> I formulated my question in general since I couldn't find an other
> message here about supporting multiple languages.
>
>> http://www.w3.org/International/articles/
>>
>> http://www.w3.org/TR/i18n-html-tech-lang/
>>
>> http://php.net/setlocale
>>
> Thanks a lot, these are good points for reading.
>>
>> 1) Switching language downloads a new version of the current page,
>> generally with the same markup but new text. Example:
>> http://partcon.ca/
>>
> I'll favor this way especially if several languages have to be provided.
>
>> In both cases I store the text in database tables that contain a
>> language field I can select on to match the user's request.
>>
> I wonder if retrieving static texts from the database draws too much
> performance. I know from somebody who stores texts in large data arrays
> an uses shared memory, yet I haven't figured it out how.
>
> I consider storing static texts as defines and just load a different
> definition file when the user switches language. Is this practical?

don't go down the define('LANG_KEY', 'lang string value'); route - defines
are comparatively SLOW to create. IF you go down the road of loading in text
from 'per lang' files I would suggest using an array as the storage mechanism:

$Lang = array(
        'LANG_KEY' => 'lang string value',
        // .. etc
);

assoc array are much less heavy to create.

also consider that there are, imho, 2 kinds of language specific data:

1. 'static' values - button texts, [error] messages - these are specified during site/application
design.

2. 'dynamic' values - document titles, headers, content - these are specified by the owner/user during
the lifetime of the site/application

for the rest I'll just say 'ditto' to most of what the other list members replied :-)

>
> O. Wyss
>

attached mail follows:


Hello all

As part of my research under my professor I have to implement a web
interface to their benchmarking data.

PHP is the chosen web language but we are little worried about the
database. The benchmark data comes to us in XML format (e.g.
http://www.matf.bg.ac.yu/~filip/ArgoLib/smt-lib-xml/Examples/FolEq1.xml).
We have to implement an interface to query them, get data, update etc.

We even can change schema in the form of attributes. . The data size
would be around 100 MB each XML with around 100 different XMLs.

The load would be max 5-10 users any given time, batch updates once a
month and heavy load probably 2-3 times a month. Mission criticality is
not important, we can get it down sometimes. Which db would you suggest?

I did Google research and as of now - I like eXist, Sedna (they seem to
have good PHP wrapper support) and Timber. Another thing would be good
documentation and support.

Any suggestions?

Ritesh

attached mail follows:


Hi

Some questions

> As part of my research under my professor I have to implement a web
> interface to their benchmarking data.
>
> PHP is the chosen web language but we are little worried about the
> database. The benchmark data comes to us in XML format (e.g.
> http://www.matf.bg.ac.yu/~filip/ArgoLib/smt-lib-xml/Examples/FolEq1.xml).
> We have to implement an interface to query them, get data, update etc.

You can parse the XML, extract the data, put it to an SQL DB and move
the XML to /dev/null (delete it).
If you do that, you don't need an XML DB.
Is this possible?

>
> We even can change schema in the form of attributes. . The data size
> would be around 100 MB each XML with around 100 different XMLs.

What do you mean by "different XMLs"?
Are you looking for a maschine that makes SQL Tables from XML?
What is inside of the 100MB XML? Your example is a MathML Formula.

>
> The load would be max 5-10 users any given time, batch updates once a
> month and heavy load probably 2-3 times a month. Mission criticality is
> not important, we can get it down sometimes. Which db would you suggest?
>
> I did Google research and as of now - I like eXist, Sedna (they seem to
> have good PHP wrapper support) and Timber. Another thing would be good
> documentation and support.

With an XML DB you can query data using XPATH. Is that the thing you
want? Oracle supports that for example.

Bernhard

attached mail follows:


Hello

Bernhard Zwischenbrugger wrote:
> Hi
>
> Some questions
>
>> As part of my research under my professor I have to implement a web
>> interface to their benchmarking data.
>>
>> PHP is the chosen web language but we are little worried about the
>> database. The benchmark data comes to us in XML format (e.g.
>> http://www.matf.bg.ac.yu/~filip/ArgoLib/smt-lib-xml/Examples/FolEq1.xml).
>> We have to implement an interface to query them, get data, update etc.
>
> You can parse the XML, extract the data, put it to an SQL DB and move
> the XML to /dev/null (delete it).
> If you do that, you don't need an XML DB.
> Is this possible?
>

No. My professor is dead against that. Many people have suggested me
doing that. Why? Are XML databases incorrectly implemented or are bad?

>> We even can change schema in the form of attributes. . The data size
>> would be around 100 MB each XML with around 100 different XMLs.
>
> What do you mean by "different XMLs"?
> Are you looking for a maschine that makes SQL Tables from XML?
> What is inside of the 100MB XML? Your example is a MathML Formula.
>

By different XMLs I meants, different XML files. So we can have 40 XML
files with around 50-100 MB each.

Yes, they will have lot sof those MathML formulas. Its benchmarking data
from some theoritical group that my professor works with. They have all
their database in XML so relational database is not possible otherwise
we will have to convert them between XML and relational all the time.

>> The load would be max 5-10 users any given time, batch updates once a
>> month and heavy load probably 2-3 times a month. Mission criticality is
>> not important, we can get it down sometimes. Which db would you suggest?
>>
>> I did Google research and as of now - I like eXist, Sedna (they seem to
>> have good PHP wrapper support) and Timber. Another thing would be good
>> documentation and support.
>
> With an XML DB you can query data using XPATH. Is that the thing you
> want? Oracle supports that for example.
>

Yeah but looking at
http://www.oracle.com/technology/tech/xml/xmldb/index.html, I could not
find whether its free. I might be wrong but the info is not easily found
there.

One the contrary IBMs offering at
http://www-306.ibm.com/software/data/db2/express/download.html looks FREE.

The problem is that both the above two database are beasts in themselves
and I just require 10% of what they do :)

We looked into Berkeley DB also but their support for PHP is not that
great. We have compile the module by ourselves etc (this is not a
problem though as we have the technical know how to do that) but lot of
people have suggested that its not a very stable system. I have not done
any benchmarking on it but I dont want to change my underlying DB couple
of months down the line just because we found out its not stable.

Apart from the above big three, the other free and reasonable good
implementation seems to be eXist, Timber and Sedna. This I am just
saying by reading their website. I have not used them.

So my question is: out of the six systems listed above, which one you
would suggest? Has anybody used any of the above system before? What are
your experiences?

> Bernhard
>

Ritesh

>

attached mail follows:


        Hi again
        
        I don't know what the DB should do for you.
        
        If you simple want to select subtrees from your big XML, you can put
        the XML Files to the filesystem and use XPointer for query.
        
        Here an example:

<?php
$xml=<<<END
<result xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xi:include href="http://www.laptop.org/vision/index.shtml#xmlns(xhtml=http://www.w3.org/1999/xhtml)xpointer(//xhtml:div[1]//xhtml:div[1])" parse="xml">
   <xi:fallback>
   <error>not found</error>
   </xi:fallback>
  </xi:include>
</result>
END;

$dom=domDocument::loadXML($xml);
$dom->xinclude();

header("Content-type:text/xml");
echo $dom->saveXML();
?>

This example loads an XML (xhtml) from the web (filesystem is also
possible) and outputs a subtree of the document.
The subtree is selected by an XPointer expression.

The XML: http://www.laptop.org/vision/index.shtml
The XPointer:
"#xmlns(xhtml=http://www.w3.org/1999/xhtml)xpointer(//xhtml:div[1]//xhtml:div[1])"
(the namespace part is a little tricki)

To parse 100MByte takes some time.
A database can improve speed, the query syntax (XPointer) maybe is the
same.
Without knowing what the output of the database should be und the query
parameters, it is not easy to tell what db is the best for you.

A solution could be to split the 100MByte file in small parts and store
the subtrees to blobs in mySql. You can build an index based on XPath
and it could be a real fast solution.

Bernhard

        

attached mail follows:


Myron Turner skrev:
> William Stokes wrote:
>> Hello,
>>
>> I need some advice on how to learn Javascript and PHP interaction. Any
>> good tutorials on the web would be most welcome. I particulary need to
>> learn how to pass JS user input/choices to PHP.
>>
>> My current problem is how to ask user confirmation over his actions on
>> a web form after POST. "Are you sure" type questions and how to pass
>> the user choice back to program make choices with PHP.
>>
>> Thanks
>> -Will
>>
>>
> For the second question try google with something like "javascript form
> submit".
>
> For the first question, see:
> http://ca.php.net/manual/en/language.variables.predefined.php
> Form data is captured in PHP in a number of different predefined
> variables accessible from your scripts. This page defines these
> varibables.
>
Use AJAX

Link: http://javascript.internet.com/ajax/ajax-navigation.html

is migth be what you are looking for:
http://javascript.internet.com/ajax/check-username-signup.html

The cool thing with AJAX is that it can load pages while viewing the
webpage. Without updating it!

check out this chat i made with it:
http://wsd.riddergarn.dk/index.php?p=chat

attached mail follows:


Hello, folks -- lurking for a while, first post --

I'm relatively new to PHP but doing database design work for nearly
20 years.

I've RTFM'ed (+ books + other resources) a bunch of times but I have
a mental block around doing this:

I want to have an multidimensional array as a property of an object.

Example:

MySQL Resource:
  WHAM_ID NAME AMOUNT
   5 Fred 99
   9 Albert 345
  23 Mary 5
  (etc...)

Inside the function which builds the instance of the object, I have
language like:

while ($line = mysql_fetch_array($result_set,MYSQL_ASSOC))
{
   $this->foom_array = array("MyKey".$line["wham_id"]=>array($line).",";
}
This isn't even close. <g>

Any examples, or a well-written resource to help me do this?

TIA

Ken

attached mail follows:


On Fri, 2007-01-26 at 15:09 -0600, Ken Kixmoeller -- reply to
kenkixmoeller.com wrote:
> Hello, folks -- lurking for a while, first post --
>
> I'm relatively new to PHP but doing database design work for nearly
> 20 years.
>
> I've RTFM'ed (+ books + other resources) a bunch of times but I have
> a mental block around doing this:
>
> I want to have an multidimensional array as a property of an object.
>
> Example:
>
> MySQL Resource:
> WHAM_ID NAME AMOUNT
> 5 Fred 99
> 9 Albert 345
> 23 Mary 5
> (etc...)
>
> Inside the function which builds the instance of the object, I have
> language like:
>
> while ($line = mysql_fetch_array($result_set,MYSQL_ASSOC))
> {
> $this->foom_array = array("MyKey".$line["wham_id"]=>array($line).",";

$this->foom_array[$line['WHAM_ID']] = $line;

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


On Jan 26, 2007, at 3:08 PM, Robert Cummings wrote:

> $this->foom_array[$line['WHAM_ID']] = $line;
>
> Cheers,
> Rob.

Thank you so much, Rob. That did it. (Kickin' the cobwebs out of my
head...)

attached mail follows:


I have a search page that displays all active records in my application, but
for some reason, I can not get it to display based on a specific input.

For instance, I have records with id's 2, 3, 4, 5 etc... In my search form,
the default view shows all records, and my form variable lets you put in
different search criteria. If I do a search by id and put in "2" as the
search condition, my results keep coming back blank. It does not matter
which parameter or value I put in, it still returns blank.

Any ideas?

<?php
 $connection = mssql_connect($host, $user, $pass) or die ('server connection
failed');
  $database = mssql_select_db("$database", $connection) or die ('DB
selection failed');

  // Query the table and load all of the records into an array.
  $query = "SELECT
     child_support_payment_request.credit_card_id,
   credit_card_payment_request.credit_card_id,
   credit_card_payment_request.date_request_received
    FROM child_support_payment_request,
         credit_card_payment_request
      WHERE child_support_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id";
 if ($request_id !== '') {
    $query.=" AND credit_card_payment_request.credit_card_id =
$request_id2";
    }
 if ($dateTime !== '') {
   $query.=" AND credit_card_payment_request.date_request_received =
$dateTime2";
   }
 $res = mssql_query($query) or die(mssql_error());

  echo "<table width='780' border='1' align='center' cellpadding='2'
cellspacing='2' bordercolor='#000000'>";

while ($rows = mssql_fetch_array($res)) {
   $res_id = $rows['credit_card_id'];
   $res_dateTime = $rows['date_request_received'];
echo "<tr>";
echo "<td width='88' height='13' align='center' class='tblcell'><div
align='center'>$res_id</div></td>";
echo "<td width='224' height='13' align='center' class='tblcell'><div
align='center'>$res_dateTime</div></td>";
echo "<td width='156' height='13' align='center' class='tblcell'><div
align='center'>Open</div></td>";
echo "<td width='156' height='13' align='center' class='tblcell'><div
align='center'>Payment Type</div></td>";
echo "<td width='156' height='13' align='center' class='tblcell'><div
align='center'>Last Processed By</div></td>";
echo "</tr>";
 }
echo "</table>";
?>

The variables $request_id and $dateTime are specified in a seperate chunk of
php code, but are still included on the same page as the code below. Am I
right in assuming that any variable set on the same page can be carried into
different php blocks on the same page?

Example:

<?php

$id = $_POST['request_id']

?>

<?php

echo "<table>";
echo "<td>"'
echo $id;
echo "</td>";
echo "</table>";

?>

That would be valid, correct?

attached mail follows:


Hey - -- -

Here I am again. Anybody still working on a Friday?

I would like to have a class instance be the property of another
class, like can be done in other languages. For example: I would like
to have a "Connections" class which contains all of the database
connection logic and query results. There are advantages to having
this type of utility class be local to a data or business class. (I
know that I could have a generic "include" with functions outside of
the class hierarchy.)

So, in the __construct method of a business or data class, for
example, one could:

include_once("connection_classes.kbk");
$this->connection_class = new connection_class;

This syntax fails, so I know this isn't right, but I hope you get the
idea.

Can it be done?

TIA, again

Ken

attached mail follows:


[snip]
I would like to have a class instance be the property of another
class, like can be done in other languages. For example: I would like
to have a "Connections" class which contains all of the database
connection logic and query results. There are advantages to having
this type of utility class be local to a data or business class. (I
know that I could have a generic "include" with functions outside of
the class hierarchy.)

So, in the __construct method of a business or data class, for
example, one could:

include_once("connection_classes.kbk");
$this->connection_class = new connection_class;

This syntax fails, so I know this isn't right, but I hope you get the
idea.

Can it be done?
[/snip]

Extends?

class new_connection extends connection {}

attached mail follows:


[snip]
This syntax fails, so I know this isn't right, but I hope you get the
idea.

Can it be done?
[/snip]

Extends?

class new_connection extends connection {}
[/snip again]

I read too fast....

A member function can be referenced by another class as long as the
function is public. You would just use it within the class as you would
call any member function.

attached mail follows:


Ken Kixmoeller -- reply to kenkixmoeller.com wrote:
> Hey - -- -
>
> Here I am again. Anybody still working on a Friday?
>
> I would like to have a class instance be the property of another class,
> like can be done in other languages. For example: I would like to have a
> "Connections" class which contains all of the database connection logic
> and query results. There are advantages to having this type of utility
> class be local to a data or business class. (I know that I could have a
> generic "include" with functions outside of the class hierarchy.)
>
> So, in the __construct method of a business or data class, for example,
> one could:
>
> include_once("connection_classes.kbk");
> $this->connection_class = new connection_class;
>
> This syntax fails, so I know this isn't right, but I hope you get the idea.

what fails? I can't smell the error your getting from here and from what I see
there should be no problem:

class Foo
{
        private $var;
        function __construct() { $this->var = "foo"; }
        function getFoo() { return $this->var; }
}

class Bar
{
        private $var;
        private $foo;
        function __construct() { $this->var = "bar"; $this->foo = new Foo; }
        function getBar() { return $this->var; }
        function speak() { echo "I am ",$this->foo->getFoo(),$this->getBar(),"\n"; }
}

$b = new Bar;
$b->speak();

>
> Can it be done?

yes. see above. :-)

>
> TIA, again
>
> Ken
>
> --PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

attached mail follows:


# Kixjaguarcomcast.net / 2007-01-26 17:18:37 -0600:
> So, in the __construct method of a business or data class, for
> example, one could:
>
> include_once("connection_classes.kbk");
> $this->connection_class = new connection_class;
>
> This syntax fails, so I know this isn't right, but I hope you get the
> idea.

And we have to guess the error message? I don't see anything wrong
with the syntax. Post a small but complete script, and the error message.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

attached mail follows:


Hey all,

We have a new project that will require pretty
robust communication between Flash and PHP, and
I've begun Googling and came across Actionscript here:

http://www.adobe.com/devnet/flash/articles/flashmx_php.html

I wonder if anyone knows anything about running
actionscript on LinuxFfirfox machines. My install
of Firefox on Debian/Fluxbox runs Flash okay, but
not the sample app on this page.

The page above had a zip file that may need to be
downloaded to your Windows machine, but my Windows
machine ran it fine.

Anyone have any experience with PHP/Actionscript
on Linux?

Thanks!
--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=

attached mail follows:


Skip Evans wrote:
> Hey all,
>
> We have a new project that will require pretty robust communication
> between Flash and PHP, and I've begun Googling and came across
> Actionscript here:
>
> http://www.adobe.com/devnet/flash/articles/flashmx_php.html
>
> I wonder if anyone knows anything about running actionscript on
> LinuxFfirfox machines. My install of Firefox on Debian/Fluxbox runs
> Flash okay, but not the sample app on this page.

probably because the flash player version on your machine is
too old?

>
> The page above had a zip file that may need to be downloaded to your
> Windows machine, but my Windows machine ran it fine.
>
> Anyone have any experience with PHP/Actionscript on Linux?

wtf?

PHP runs on the webserver, actionscript run inside a Flash 'object' which
itself runs in the webbrowser on the client.

the communication between flash and php is via our friend HTTP.
flash makes requests to the webserver just as the browser would and the
requested scripts on the webserver stip out data (usually XML) back to
flash ... you use actionscript code inside flash to make the request and
parse the returned data.

flash is platform independent - you create a flash file with actionscript code in
it (and whatever else is relevant, in terms of animation, etc), you compile it into
an SWF file and that file weill run in any browser with a flash player (with the
caveat that some flash functionality is only available in newer version of
the flash player.

>
> Thanks!

attached mail follows:


Jochem Maas wrote:
>>Anyone have any experience with PHP/Actionscript on Linux?
>
>
> wtf?

Oh my God. What am I thinking? Please folks, I am
really not this stupid. It has been too, too long
a day. Yes, I just need to upgrade Flash on this
workstation.

Skip
--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=

attached mail follows:


Hello,

Does anyone know of a script that can create an ACH origination file with
PHP?

Thanks
Dan