Re: [PHP-DB] Efficiency of DDD programing

2011-11-20 Thread Tamara Temple
Fanda  wrote:

> how to solve this problem:
> 
> If I write a repository for each entity, article and autor for
> example, article is composed of autor and some other things, then I
> want to select some articles: 
> 
> $articles = $articleRepo->findLast(10);
> foreach ($articles as $article) {
> // echo article content
> ...
> // echo
> $article->getAutor(); // next query into database, in each cycle
> }
> 
> Is some elegant way, how to do this (optimise)?

The full extent of doing this is way beyond an email list. Not knowing
how much you already know about object-oriented programming PHP or in
general, it's a bit hard to guide you. Also, it's a bit unclear whether
you're asking about how to implement the database, the interaction with
the database, writing PHP classes, or what, exactly.

Certainly, what you've outlined above is quite possible in PHP, and from
a mainline code point-of-view, fairly concise. The heavy lifting will be
done in the classes you set up for the article repository itself. From
what you've said above, there are at least four classes you'll have to
write:

1. an article repository class
2. an article class
3. an author class
4. an entity class (although it's in no way clear what you mean by
entity from the above description.)

It will be important to define relationships between these classes, from
what little I can gleen, the following looks like it might work:

* An article repository has many articles
* An article has one or many authors
* Still no clue how entity relates to articles or authors

You'll need to design data base tables that correspond to these classes
as well.

There is potentially another class you could write which deals with all
the underlying details of the database interaction itself, but you
should look at PDO[1] before you go about writing one yourself. PDO may
be all you need for this.

You might avail yourself of a framework that deals with database objects
under the hood rather than write all this yourself as well, although
doing that will probably not be as instructive as writing your own. The
decision may rest with how much time you have to invest in learning
what. It's not an exact tradeoff, because all the frameworks also
require a learning curve to use them.

[1] http://us.php.net/manual/en/book.pdo.php

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



Re: [PHP-DB] Efficiency of DDD programing

2011-11-20 Thread Karl DeSaulniers
foreach ($articles as $author => $article) {
echo("author".$i." =".$author."article=".$article);
}

I think. I could be corrected. Not to mention, did you mean to spell your 
function like this? getAutor? Or did you mean getAuthor?

HTH,

Best,
Karl

Sent from losPhone

On Nov 20, 2011, at 8:24 AM, "Fanda"  wrote:

> Hi,
> how to solve this problem:
> 
> If I write a repository for each entity, article and autor for example, 
> article is composed of autor and some other things, then I want to select 
> some articles:
> 
> $articles = $articleRepo->findLast(10);
> foreach ($articles as $article) {
>// echo article content
>...
>// echo
>$article->getAutor(); // next query into database, in each cycle
> }
> 
> Is some elegant way, how to do this (optimise)?
> 
> Thank you.
> F.
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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



[PHP-DB] Efficiency of DDD programing

2011-11-20 Thread Fanda
Hi,
how to solve this problem:

If I write a repository for each entity, article and autor for example, article 
is composed of autor and some other things, then I want to select some articles:

$articles = $articleRepo->findLast(10);
foreach ($articles as $article) {
// echo article content
...
// echo
$article->getAutor(); // next query into database, in each cycle
}

Is some elegant way, how to do this (optimise)?

Thank you.
F.

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



[PHP-DB] Efficiency question

2003-06-26 Thread Micah Stevens
I would guess that:

$data = mysql_fetch_assoc(mysql_query("select * from some_table limit 1"));

would be faster than:

$pointer = mysql_query("select * from some_table limit 1");
$data = mysql_fetch_assoc($pointer);

but I'm not sure, php may optimize this. Anyone know the answer?

I'm taking over some code that someone else made that has a lot of one record 
retrevals coded in it, like option 2, and I was wondering if it was worth my 
time to change it. 

Thanks!
-Micah


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



Re: [PHP-DB] Efficiency

2003-01-21 Thread Paul Burney
on 1/21/03 6:16 AM, Baumgartner Jeffrey at [EMAIL PROTECTED]
appended the following bits to my mbox:

> 1. If I am creating a web page with numerous PHP calls to an MySQL database
> is it more efficient to have lots of small blocks of php in an html page or
> is it better to have just one or two big blocks of PHP with the html code
> being delivered via echo statements?

This gets discussed very frequently here and in PHP-General.  Check the
archives for the discussions, but the general consensus is that it doesn't
matter much.

I tend more toward the echo statements (FYI: use commas rather than dots)
because for me, the code looks nicer with syntax highlighting.

If you don't hand code your HTML (i.e., use Dreamweaver, GoLive, etc), the
small php blocks might be easier to manage.

> 2. If I want to know how many rows there are in a MySQL table, I can either
> use the count function in MySQL (although I am having trouble figuring out
> how to capture that value in a variable) or I can do a general "select *
> from" from command in MySQL and then use the mysql_num_rows function in PHP
> to get a row count (which is dead easy). It SEEMS to me the former would be
> more efficient. Am I correct?

If you are doing a select on the data anyway, it is better to call
MySQL_num_rows on the result you obtained.  If you just want the total
number and won't be fetching the rows, do the query.  Example:

$dbh is your database connection
$q = 'SELECT COUNT(*) FROM tablename';
list($my_count) = MySQL_fetch_row(MySQL_query($q,$dbh));

The $my_count variable now has your number of rows.

Hope that helps.

Sincerely,

Paul Burney


Q: Tired of creating admin interfaces to your MySQL web applications?

A: Use MySTRI instead. 



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




[PHP-DB] Efficiency

2003-01-21 Thread Baumgartner Jeffrey
A couple of questions of efficiency, please:

1. If I am creating a web page with numerous PHP calls to an MySQL database
is it more efficient to have lots of small blocks of php in an html page or
is it better to have just one or two big blocks of PHP with the html code
being delivered via echo statements?

2. If I want to know how many rows there are in a MySQL table, I can either
use the count function in MySQL (although I am having trouble figuring out
how to capture that value in a variable) or I can do a general "select *
from" from command in MySQL and then use the mysql_num_rows function in PHP
to get a row count (which is dead easy). It SEEMS to me the former would be
more efficient. Am I correct? 

Many thanks! 

Jeffrey Baumgartner

eBusiness Consultant - ITP Europe
http://www.itp-europe.com
[EMAIL PROTECTED]
+32 2 721 51 00


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