PHP OOP - MySQL connection from within a class -


i'm sorry if wrong place, seems questions rather conceptual, it's harder browse related opened topics.

anyway, here's issue: own small e-commerce company (in brazil) , need track shipments in 1 place , want aware of possible delays , other events take place products company ships, according own criteria.

the post office provides api , have managed retrieve information each event related shipment.

i have created database in have, among others, 2 tables: 1 shipment (tracking code, destination , other stuff) , events take place.

i have created 2 classes, corresponds these 2 tables: 1 called shipments other events (obviously). believe there's no need create second table, everytime load page events loaded post office website, however, , first question, believe script run lot faster if doen't need retrieve data internet everytime, right? besides that, figured using database makes easier process data using mysql queries. make sense?

the third , important question implementation of methods of these classes. when script runs, retrives data shipments table , i'm not sure whether connect , retrive information within (inside) shipment class itself, or if should connect outside , provide class results of queries , let rest.

i figured connecting database shipments class makes less flexible (i don't believe should handled there), however, seems, @ first, lot easier create method inside class connects bd, loops through results (querying other table's data calculate how many days deadline), instantiating (from within class) , returning array objects further manipulation. make sense??

i can't figure out 1 "correct" option.

i'd apreciate if me out that.

thanks much.

this regarding third question ...

i think should implement separate layer (you can class) far data retrieving concerned ..the reason being , maintainable , scalable in future ( eg retrieving data above mentioned class , using in class reporting purpose) , shipment class should implement business logic applying on data retrieved through above mentioned class. in way have build 2 separate layers 1 model layer , other controller ( follows mvc approach ) , in view right approach design system.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -