Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Satyam


- Original Message - 
From: "Larry Garfield" <[EMAIL PROTECTED]>

To: 
Sent: Saturday, January 27, 2007 12:18 AM
Subject: Re: [PHP] SQL Readability.. (was Re: most powerful php editor)



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





I tried the following:

insert('sometable',array('when' => mktime(0,0,0,2,1,2007),'if' => true));

which produced the following SQL statement:

INSERT INTO sometable (when) VALUES (1170284400,1170284400)

The problem is that PHP types do not correspond to SQL types.  Though a 
boolean does identify itself as such, a date never does.  Your switch() on 
the gettype() of the value misses the type 'boolean' so it falls through the 
default: case which then appends whatever was left from the previous pass. 
However, even adding a case for type boolean there is no way to recognize 
dates since they are no more than integers for all PHP cares.  Finally, what 
happens with an expression that produces a sort-of boolean, like anything 
non-zero for true?


Those are the reasons I used type modifiers in my BuildSql function 
(http://www.satyam.com.ar/int/BuildSql.php), I couldn't rely on PHP figuring 
them out correctly.  This also allowed me  to expand those modifiers to 
optional positional modifiers and null handling ones.


I even tried to query the SQL engine to report them back, but that was also 
unreliable, MySql for one, reports the type of what it used to store it, not 
what you declared them to be.  Thus, for a boolean field it will report 
integer, but if you try to store a number other than 0 or 1 it then 
complains.   So, unable to get reliable information from either end, I 
decided on stating the type explicitly on the query string.


Satyam



On Friday 26 January 2007 10:03 am, [EMAIL PROTECTED] 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:
>> > # [EMAIL PROTECTED] / 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 tab

[PHP] Rory Browne from this php list (0.T)

2007-01-27 Thread Ryan A
Hello!

As some of you might remember: a little while back I had a project to be done 
in PHP, which I asked if anyone on the list would be interested in completing 
for $800 USD.

Rory Browne from the list got the job and around the 15th of Jan he told me he 
completed the work and was going to send me/setup the software but then I did 
not get any word from him after multiple emails in the days since, am wondering 
if something bad happened to him... (hope not)

Does anyone know Rory Browne's phone number or any other contact details?

Thanks,
Ryan


--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

-
Everyone is raving about the all-new Yahoo! Mail beta.

Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Jochem Maas
Larry Garfield wrote:
> 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
> 

a quick look at those funcs gives me the impression that they are woefully
inadequate for any level of complex realworld use.

query builders are alot more fiddly to get 'right' than one might imagine,
dealing with NULLs, booleans and dates for example (as Satyam pointed out)
can be a right PITA.

perfect automated CRUD (it's an acronym!) is kind a holy grail - and
that is, I think, the driving force behind most attempts to crteate query 
builders.

also I don't really agree with the sentiment that SQL syntax is nasty,
personally I find it, mostly, very easy to read and powerful ... but as this
thread shows there is no accounting for taste! :-)

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



Re: [PHP] PHP & Flash

2007-01-27 Thread Jochem Maas
Skip Evans wrote:
> Jochem Maas wrote:
>>> Anyone have any experience with PHP/Actionscript on Linux?
>>
>>
>> wtf?

ah ok, so the idiots guide to flash/php interaction wasn't really needed :-)

> 
> 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.
> 

glad you got it sorted.

> Skip

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



Re: [PHP] Create ACH Origination file with PHP

2007-01-27 Thread Jochem Maas
Dan Harrington wrote:
> Hello,
> 
> Does anyone know of a script that can create an ACH origination file
> with PHP?

SingTFW didn't turn up anything for php but maybe the following perl module
might help you to write the equivelant in php:

http://search.cpan.org/~tkeefer/ACH-Builder-0.02/lib/ACH/Builder.pm

> 
> Thanks
> Dan
> 

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



Re: [PHP] Result sorting not working

2007-01-27 Thread Jochem Maas
Dan Shirah wrote:
> 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?

you don't bother to read your own code thoroughly? see below:

> 
>  $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";

$request_id AND $request_id2 ??

>}
> if ($dateTime !== '') {
>   $query.=" AND credit_card_payment_request.date_request_received =
> $dateTime2";

$dateTime AND $dateTime2 ??

...

ecified 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:
> 
>  
> $id = $_POST['request_id']
> 
> ?>
> 
>  
> echo "";
> echo ""'
> echo $id;
> echo "";
> echo "";
> 
> ?>
> 
> That would be valid, correct?

yes.

> 

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



Re: [PHP] php & javascript interaction

2007-01-27 Thread Jochem Maas
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.

http://php.net/json
http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

^^-- note the name! toys.lerdorf.com is a veritable goldmine of
funky info, lots of php magic to be had there.


> 
> Thanks
> -Will
> 

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



[PHP] navigation

2007-01-27 Thread koen
How to creat the effect of the explorers back and forward buttons in php?

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



RE: [PHP] navigation

2007-01-27 Thread Jay Blanchard
[snip]
How to creat the effect of the explorers back and forward buttons in
php?
[/snip]

Since PHP is server side you would have to use Javascript to do this.
See 
http://www.comptechdoc.org/independent/web/cgi/javamanual/javahistory.ht
ml
 

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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Edward Kay



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.
This fails simply because you've omitted the parentheses on the 
constructor. It should be:


$this->connection_class = new connection_class();

Of course, you may want/need to pass some arguments here too.

As mentioned by others though, for the scenario you describe above, you 
would probably be better extending a base class.


Edward


Can it be done?

TIA, again

Ken

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






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



RE: [PHP] Create ACH Origination file with PHP

2007-01-27 Thread Jay Blanchard
[snip]
Does anyone know of a script that can create an ACH origination file
with 
PHP?[/snip]

How do you want to input amounts, routing numbers, and account numbers?
Have you checked out the NACHA file specifications? http://www.nacha.org
Do you need to perform file encryption before you transmit? How will you
transmit (FTP, SFTP, web service)? This is a simple question with many
variables.

Essentially the ACH file is a text file that is reasonably easy to
create with PHP and you can use either a database or file I/O or XML to
input amounts, routing, etc. 

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



Re: [PHP] navigation

2007-01-27 Thread Myron Turner

koen wrote:

How to creat the effect of the explorers back and forward buttons in php?

  


It's a javascript issue, using the javascript history object.

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Robert Cummings
On Sat, 2007-01-27 at 14:43 +0100, Jochem Maas wrote:
>
> also I don't really agree with the sentiment that SQL syntax is nasty,

Hear, hear :)

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.  |
`'

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Larry Garfield
On Saturday 27 January 2007 7:43 am, Jochem Maas wrote:
> Larry Garfield wrote:
> > 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
>
> a quick look at those funcs gives me the impression that they are woefully
> inadequate for any level of complex realworld use.

That's interesting, because I've been using variants of that for a year now 
with much success in a dozen projects.  

> query builders are alot more fiddly to get 'right' than one might imagine,
> dealing with NULLs, booleans and dates for example (as Satyam pointed out)
> can be a right PITA.

I actually almost never use native date types in the SQL database.  I just 
store unix timestamps and do the math in PHP.  Dates are completely 
unportable anyway.  I also tend to use ints for booleans, too, although 
beefing up the switch statements in the code to handle native booleans should 
be trivial.  

> perfect automated CRUD (it's an acronym!) is kind a holy grail - and
> that is, I think, the driving force behind most attempts to crteate query
> builders.

Orthogonal persistence is, yes.  The goal here was simply to make dealing with 
arbitrary insert and update statements easier, which in practice I've found 
to be a huge success.  Full arbitrary CRUD and orthogonal persistence is much 
harder.  That's why there's a dozen ORMs out there, all of which have some 
major flaw. :-)  

> also I don't really agree with the sentiment that SQL syntax is nasty,
> personally I find it, mostly, very easy to read and powerful ... but as
> this thread shows there is no accounting for taste! :-)

What bugs me most about SQL syntax is INSERT vs. UPDATE.  I don't know the 
underlying implementation details of the engine, but from the level I work at 
(sending SQL to a database from a web app) I see no legitimate reason why 
those two very-similar statements should have ridiculously different syntax.  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   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

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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Jochem Maas
Edward Kay 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.
> This fails simply because you've omitted the parentheses on the
> constructor. It should be:
> 
> $this->connection_class = new connection_class();

WRONG - the parentheses are optional - my example in a a previous reply
to this thread proves this (if you care to test it).

> 
> Of course, you may want/need to pass some arguments here too.
> 
> As mentioned by others though, for the scenario you describe above, you
> would probably be better extending a base class.

I see no real justification for class extension at this stage, it *may* be the 
best
way to tackle this situation BUT there may be good reasons that the class in 
question
lives in it's own seperate class heirarchy.

object aggregation is just as valid as class extending in principle.

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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Ken Kixmoeller -- reply to [EMAIL PROTECTED]
Thanks for your help, guys. I had to leave my office last evening  
before I had a chance to try any of them.


I am sneaking in some office time today. I'll let you know (with  
complete scripts and error messages).


Ken

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



[PHP] Sporadic MSSQL connection error

2007-01-27 Thread kentozier
Hi

I'm having a sporadic connection problem with MSSQL. I have a php script which 
is called by a folder scanning application and sometimes it can run for hours 
without problem but other times it will run for just a few minutes and return 
connection errors. I tried using mssql_get_last_message but it always seems to 
return an empty string.

I'd like to find out why the connection is failing but in the absense of error 
info from MSSQL, it's a bit problematic. Is there a creative way to actually 
get error strings back from MSSQL in light of the fact that 
mssql_get_last_message basically does squat?

As a last ditch effort, I could run the connect line in a loop a set number of 
times until it succeeds but I would prefer to know why it fails.

Can anyone offer suggestions?

Thanks

Ken

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



RE: [PHP] Create ACH Origination file with PHP

2007-01-27 Thread Jay Blanchard
[snip]
I am familiar with the NACHA file format, and have the specifications, I
just would rather not write the file formatter and output if someone
else
has done it already or could do it more easily than I.
Do you have experience in this? 
[/snip]

Ah. Yes I do have experience in this and have done it several times over
the years. I have never made the code public typically because I would
have to edit sensitive information out of it.

Here is an example, edited with comments about where stuff should occur,
since this has been edited it has not been tested and may require
significant modification to work in any case (it includes being able to
keep a log); 

/*
  * includes
  */
include("your database connection");
/* 
 * create the ACH transfer request records to be transmitted
 * each batch must contain
 *  file header record
 *  company/batch header record
 *  detail record(s)
 *  addenda record(s) OPTIONAL
 *  company/batch control record
 *  file control record
 * 
 * all alphanumeric and alpha characters must be upper case with fields
left justified, and blank filled
 * all numeric fields must be right justified, unsigned, and zero filled
 * 
 * detail records will be created first so that appropriate details can
be gathered for header and control records
 * 
 */  
  
 /* 
  * entry detail records
  * this is requires a loop
  * we will loop through each dealer's daily records for the day in
question and sum the dollar amount that they owe us.
  * we will have one detail record for each dealer each day that has
a total > 0
  * we will then get their banking info and create the detail record
  * if there is no banking info we will not run a detail record
  */
  
  $getDealerAcct = "your query for account info ";
  if(!($dbDealerAcct = mysql_query($getDealerAcct, $dbc))){
echo mysql_error();
exit();
  }
  /* get number of rows */
  if(0 != mysql_num)
  /* loop through detail records */
 
 $detailRecCount= 0; //initialize record count
 $detailHash= 0; //initialize detail hash
 $totBatchDollar= 0; //initialize batch dollars
 $totBlockCount = 0; //initailize block count
 $totEntryRecord= 0; //initailize block count
 $dollar = ''; // initialize amount
 $startDate = date("Y-m-d", strtotime("-2days")); //The start date
should be two days ago
 if($_GET['date']!=''){
$startDate = $_GET['date'];
 }

 $endDate = $startDate; //The end date should be the same as the start
date
 
 $txtLog = "Dealer Code\tDealer Name\tAmount\n"; // header code for log
file
 $logLine = ""; //initializing line
 
 while($dealerAcct = mysql_fetch_array($dbDealerAcct)){
 
 //20060906jc  Here let's find the correct dollar amount for what we are
looking for
 $dealerCode = $dealerAcct['dealerCode'];
 $logLine.= $dealerCode."\t";
 $sqlGetName = "get account name";
 if(!($dbGetName = mysql_query($sqlGetName, $dbc))){
echo "Error Getting
Name!(".mysql_errno()."):".mysql_error()."\n";
echo $sqlGetName."\n";
exit();
 }
 $arrGetName =  mysql_fetch_assoc($dbGetName);
 $dealerName = $arrGetName['dealerDBA'];
 if($dealerName==""){
$dealerName="[none given]";
 }
 $logLine.= $dealerName."\t";


 $sqlGetMoola = "query to get amount associated with account ";
 if(!($dbGetMoola = mysql_query($sqlGetMoola, $dbc))){
echo "Error Getting tha
Moola!(".mysql_errno()."):".mysql_error()."\n";
echo $sqlGetMoola."\n";
exit();
 }
 $dollar = 0;
 $index = 0;
 $intGetMoola = mysql_num_rows($dbGetMoola);
 while($index < $intGetMoola){
$arrGetMoola = mysql_fetch_array($dbGetMoola);
$dollar = $dollar + $arrGetMoola['amount'];
$index++; 
 }
 $logLine.= $dollar."\n";
 //echo $logLine;
 if($dollar!=0){
$txtLog.=$logLine;
 }
 $logLine = "";
 $dollar = $dollar * 100;
 
 if($dollar != 0){
$detailRecord .='6';
$detailRecord .='27'; // transaction code
$detailRecord .=substr($dealerAcct['dealerABARoute'], 0,
8); // ABA routing number (first eight characters)
$detailRecord .=substr($dealerAcct['dealerABARoute'], 8,
1); // routing number check digit (ninth character in routing number)
$detailRecord .=str_pad($dealerAcct['dealerABAAccount'],
17, " ", STR_PAD_RIGHT); // account number, left justify blank fill
$detailRecord .=str_pad($dollar, 10, "0", STR_PAD_LEFT);
// amount
$detailRecord .=str_pad('', 15, " ", STR_PAD_RIGHT); //
individual id number
$detailRecord .=
str_pad(substr(strtoupper($dealerAcct['dealerDBA']), 0, 22), 22, " ",
STR_PAD_RIGHT); // individual name
$detailRecord .=str_pad('', 2, " ", STR_PAD_RIGHT); //
BoA draft indicator
$detailRecord .='0'; // addenda indicator
$detailRecord .=str_pad('', 15, "0", STR_PAD_LEFT);
//Trace Number

[PHP] My objects eats too much (and weird!) memory

2007-01-27 Thread Francisco M. Marzoa Alonso
Hello!

I'm new here, so I do not know if attachments are allowed, so I put my
code below.

I've written this to check memory consumption of PHP5 objects, because
I'm having memory problems with an OO XMLParser that I've written.

When I execute the code from cli, I get:



$ php MemTest.php
Obj1 uses 208 bytes
Obj2 uses 168 bytes
Obj3 uses 200 bytes
Obj4 uses 200 bytes
Obj5 uses 200 bytes
Obj6 uses 200 bytes


I understand that first instance may be bigger than next ones because
method allocation and other things of that kind, but I do not understand
why second instance is smaller than third :-?

So, my first question is: Why third object is a 16% smaller than third
and nexts?

In any case, my second question is: Isn't too much memory 200 bytes for
a so simply object??


And the third: Is there any manner to get more compact objects in PHP5?


Thanks a lot in advance.

---
a = $a;
}
}

$before=0;
$memdiff=0;

$before = memory_get_usage();
$obj1 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj1 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj2 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj2 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj3 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj3 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj4 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj4 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj5 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj5 uses $memdiff bytes\n";

$before = memory_get_usage();
$obj6 = new dummy (0);
$memdiff = memory_get_usage()-$before;
echo "Obj6 uses $memdiff bytes\n";


?>

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



Re: [PHP] My objects eats too much (and weird!) memory

2007-01-27 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-26 20:40:34 +0100:
> I've written this to check memory consumption of PHP5 objects, because
> I'm having memory problems with an OO XMLParser that I've written.

It measures something else though. The memory manager doesn't allocate
memory for individual variables in PHP.

> $ php MemTest.php
> Obj1 uses 208 bytes
> Obj2 uses 168 bytes
> Obj3 uses 200 bytes
> Obj4 uses 200 bytes
> Obj5 uses 200 bytes
> Obj6 uses 200 bytes
> 
> 
> I understand that first instance may be bigger than next ones because
> method allocation and other things of that kind

No.

> but I do not understand why second instance is smaller than third :-?

It's not.
 
> In any case, my second question is: Isn't too much memory 200 bytes for
> a so simply object??

It's not memory consumption of that object.

> And the third: Is there any manner to get more compact objects in PHP5?

You need to measure something before you want to compare it ("more
compact" than what?)


> class dummy {
>   protected $a;
> 
>   public function __construct ( $a ) {
>   $this->a = $a;
>   }
> }
> 
> $before=0;
> $memdiff=0;
> 
> $before = memory_get_usage();

What's $before here?

> $obj1 = new dummy (0);
> $memdiff = memory_get_usage()-$before;
> echo "Obj1 uses $memdiff bytes\n";
> 
> $before = memory_get_usage();

What's $before here?

> $obj2 = new dummy (0);
> $memdiff = memory_get_usage()-$before;
> echo "Obj2 uses $memdiff bytes\n";

-- 
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

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



Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Jochem Maas
Larry Garfield wrote:
> On Saturday 27 January 2007 7:43 am, Jochem Maas wrote:
>> Larry Garfield wrote:
>>> 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
>> a quick look at those funcs gives me the impression that they are woefully
>> inadequate for any level of complex realworld use.
> 
> That's interesting, because I've been using variants of that for a year now 
> with much success in a dozen projects.  

I was nitpicking - I'm quite sure they are useful within the bounds of the
intended scope and wielded by a pair of hands that knows the code intimately
(including any limitations).

I run plenty of stuff that falls in the same category :-)

> 
>> query builders are alot more fiddly to get 'right' than one might imagine,
>> dealing with NULLs, booleans and dates for example (as Satyam pointed out)
>> can be a right PITA.
> 
> I actually almost never use native date types in the SQL database.  I just 
> store unix timestamps and do the math in PHP.  Dates are completely 
> unportable anyway.  I also tend to use ints for booleans, too, although 
> beefing up the switch statements in the code to handle native booleans should 
> be trivial.  

mysql doesn't have booleans does it? at least not versions I have to use.
with regard to date stuff, many people take the opposite approach and do most of
the date math inside SQL - most DBs have kickass date calculation functions btw.

and for the times when you need/want unix timestamps, mysql atleast, gives you
UNIX_TIMSTAMP().

(just some loose thoughts)

> 
>> perfect automated CRUD (it's an acronym!) is kind a holy grail - and
>> that is, I think, the driving force behind most attempts to crteate query
>> builders.
> 
> Orthogonal persistence is, yes.  The goal here was simply to make dealing 
> with 
> arbitrary insert and update statements easier, which in practice I've found 
> to be a huge success.  Full arbitrary CRUD and orthogonal persistence is much 
> harder.  That's why there's a dozen ORMs out there, all of which have some 
> major flaw. :-)  

including mine :-) (not released because it, well, needs a big manual that
only exists in my head - besides is firebird/ibase specific and I'm one of
about 5 people who actually use php+firebird :-)

> 
>> also I don't really agree with the sentiment that SQL syntax is nasty,
>> personally I find it, mostly, very easy to read and powerful ... but as
>> this thread shows there is no accounting for taste! :-)
> 
> What bugs me most about SQL syntax is INSERT vs. UPDATE.  I don't know the 
> underlying implementation details of the engine, but from the level I work at 
> (sending SQL to a database from a web app) I see no legitimate reason why 
> those two very-similar statements should have ridiculously different syntax.  

granted it's not perfect, somebody made a design 'fault' way back when and we're
stuck with it. maybe someone else has some real info about why this is so.

> 

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



Re: [PHP] My objects eats too much (and weird!) memory

2007-01-27 Thread Francisco M. Marzoa Alonso
On sáb, 2007-01-27 at 20:05 +, Roman Neuhauser wrote:
> # [EMAIL PROTECTED] / 2007-01-26 20:40:34 +0100:
> > I've written this to check memory consumption of PHP5 objects, because
> > I'm having memory problems with an OO XMLParser that I've written.
> 
> It measures something else though. The memory manager doesn't allocate
> memory for individual variables in PHP.
> 
> > $ php MemTest.php
> > Obj1 uses 208 bytes
> > Obj2 uses 168 bytes
> > Obj3 uses 200 bytes
> > Obj4 uses 200 bytes
> > Obj5 uses 200 bytes
> > Obj6 uses 200 bytes
> > 
> > 
> > I understand that first instance may be bigger than next ones because
> > method allocation and other things of that kind
> 
> No.
> 
> > but I do not understand why second instance is smaller than third :-?
> 
> It's not.
>  
> > In any case, my second question is: Isn't too much memory 200 bytes for
> > a so simply object??
> 
> It's not memory consumption of that object.


AFAIK there's no other way to measure memory usage on PHP than this, if
you know something better it could be more constructive if you show it.

> 
> > And the third: Is there any manner to get more compact objects in PHP5?
> 
> You need to measure something before you want to compare it ("more
> compact" than what?)

If I say that I need a more compact car I think everyone understands me
without needing to say "than the one I own", so I think its pretty clear
what I'm asking for.
 
> > $before = memory_get_usage();
> 
> What's $before here?

Memory consumption until next code.

> 
> > $obj1 = new dummy (0);
> > $memdiff = memory_get_usage()-$before;
> > echo "Obj1 uses $memdiff bytes\n";
> > 
> > $before = memory_get_usage();
> 
> What's $before here?

The same as $before of before.

Thank you by your helpless comment.



signature.asc
Description: This is a digitally signed message part


[PHP] Re: My objects eats too much (and weird!) memory

2007-01-27 Thread Colin Guthrie
Francisco M. Marzoa Alonso wrote:
> AFAIK there's no other way to measure memory usage on PHP than this, if
> you know something better it could be more constructive if you show it.

The last time I looked I think the xdebug module allowed you to get the
memory consumption of a given object in PHP. I can't remember for sure
tho', so check the docs/API before spending too much time with it :)

HTH

Col.

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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Ken Kixmoeller -- reply to [EMAIL PROTECTED]
OK, Jochem, I adapted your example and got it working. Thank you very  
much.


I am still playing with it to better understand. One thing I don't  
yet understand is the necessity for the getFoo()/getBar()  
"handshake," especially the getbar() in the BAR class. That doesn't  
seem to serve any purpose. My adaptation us just a getDummy().


Do they just serve to pass the object by reference?


Ken

--
On Jan 26, 2007, at 5:47 PM, Jochem Maas wrote:




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"; }

}




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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Myron Turner

Ken Kixmoeller -- reply to [EMAIL PROTECTED] wrote:
OK, Jochem, I adapted your example and got it working. Thank you very 
much.


I am still playing with it to better understand. One thing I don't yet 
understand is the necessity for the getFoo()/getBar() "handshake," 
especially the getbar() in the BAR class. That doesn't seem to serve 
any purpose. My adaptation us just a getDummy().


Do they just serve to pass the object by reference?


Ken

--
On Jan 26, 2007, at 5:47 PM, Jochem Maas wrote:




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"; }

}




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




Assigning another class to a class variable is a standard OO technique, 
so it's not surprising that it's implemented in PHP.  I believe it's 
called "composition", though that term seems to have a wider definition.


What is it that seems odd about what you call the getFoo()/getBar() 
"handshake" ?  Actually, what do you mean by that?  I could be missing 
something, but at the moment the two classes and their calls seem pretty 
straight-forward.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Jochem Maas
Ken Kixmoeller -- reply to [EMAIL PROTECTED] wrote:
> OK, Jochem, I adapted your example and got it working. Thank you very much.
> 
> I am still playing with it to better understand. One thing I don't yet
> understand is the necessity for the getFoo()/getBar() "handshake,"
> especially the getbar() in the BAR class. That doesn't seem to serve any
> purpose. My adaptation us just a getDummy().
> 
> Do they just serve to pass the object by reference?

no - the whole piece of code was just a silly example to show you
that you can stuff an object into the property of another object.

objects are always by reference in php5 - in php4 you have to
use the 'reference' operator (the @ symbol) to make object be passed by 
reference.

your original question showed a new object being made in the constructor
of another object - that is fine but it seems a little pointless to
worry about referencing some 'global' [connection] object in each relevant
class when you seem to be creating a new object in each constructor.

try this example (I assume you use php5 - which I think you are because
you mentioned using the __construct() method which is a php5 only bit of
functionality):

userCnt++; }
function getUC() { return $this->userCnt;  }
}

class DOExample {
private $dbconn;

function __construct() {
$this->dbconn = getDBConn();
$this->dbconn->incrementUC();
}
}

function getDBConn() {
static $conn;

if (!isset($conn))
$conn = new DBConn();

return $conn;
}

$a = new DOExample;
$c = new DOExample;
$b = new DOExample;

$d = getDBConn();
echo $d->getUC(),"\n";

?>

> 
> 
> Ken
> 
> --
> On Jan 26, 2007, at 5:47 PM, Jochem Maas wrote:
> 
> 
>>
>> 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"; }
>> }
>>
>>
> 
> --PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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



Re: [PHP] Re: My objects eats too much (and weird!) memory

2007-01-27 Thread Francisco M. Marzoa Alonso
Hello,

I took a look to www.xdebug.org and the only memory related functions
was those I found here:

http://www.xdebug.org/docs-functions.php#tracing

int xdebug_memory_usage()
int xdebug_peak_memory_usage() 

The first seems to be the same that memory_get_usage 

http://es2.php.net/manual/en/function.memory-get-usage.php

that I'm using on my script, and the second seems to be just like
memory_get_peak_usage:

http://es2.php.net/manual/en/function.memory-get-peak-usage.php

That has no sense for this test.

Thanks anyway.

On sáb, 2007-01-27 at 20:46 +, Colin Guthrie wrote:
> Francisco M. Marzoa Alonso wrote:
> > AFAIK there's no other way to measure memory usage on PHP than this, if
> > you know something better it could be more constructive if you show it.
> 
> The last time I looked I think the xdebug module allowed you to get the
> memory consumption of a given object in PHP. I can't remember for sure
> tho', so check the docs/API before spending too much time with it :)
> 
> HTH
> 
> Col.
> 


signature.asc
Description: This is a digitally signed message part


Re: [PHP] SQL Readability.. (was Re: most powerful php editor)

2007-01-27 Thread Larry Garfield
On Saturday 27 January 2007 1:14 pm, Jochem Maas wrote:

> >> query builders are alot more fiddly to get 'right' than one might
> >> imagine, dealing with NULLs, booleans and dates for example (as Satyam
> >> pointed out) can be a right PITA.
> >
> > I actually almost never use native date types in the SQL database.  I
> > just store unix timestamps and do the math in PHP.  Dates are completely
> > unportable anyway.  I also tend to use ints for booleans, too, although
> > beefing up the switch statements in the code to handle native booleans
> > should be trivial.
>
> mysql doesn't have booleans does it? at least not versions I have to use.
> with regard to date stuff, many people take the opposite approach and do
> most of the date math inside SQL - most DBs have kickass date calculation
> functions btw.
>
> and for the times when you need/want unix timestamps, mysql atleast, gives
> you UNIX_TIMSTAMP().

At least as of MySQL 4.1 (haven't played with MySQL 5 much yet), yes, MySQL 
has no native boolean data type that I know of.  The standard alternative is 
TINYINT(1), which technically gives you values 0-9.  

And yes, I agree that MySQL has fairly decent date manipulation routines.  But 
at work we do try for database independence when possible, so except on 
specific projects we try to avoid it.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   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

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



[PHP] DATE

2007-01-27 Thread Ron Piggott
I have date in the variable $date_reference in the format -MM-DD.
How do I find out the date before this and the date after this?  Ron

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



Re: [PHP] DATE

2007-01-27 Thread Casey Chu

Read http://us3.php.net/manual/en/function.strtotime.php.

It might help.

On 1/27/07, Ron Piggott <[EMAIL PROTECTED]> wrote:

I have date in the variable $date_reference in the format -MM-DD.
How do I find out the date before this and the date after this?  Ron

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




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



Re: [PHP] DATE

2007-01-27 Thread Francisco M. Marzoa Alonso
On sáb, 2007-01-27 at 23:51 -0500, Ron Piggott wrote:
> I have date in the variable $date_reference in the format -MM-DD.
> How do I find out the date before this and the date after this?  Ron
> 


http://us3.php.net/manual/en/function.date.php#68716

RTFM :-P


signature.asc
Description: This is a digitally signed message part