mysql - Object Oriented PHP: Loading data from DB to create objects? -


i new oop in php here goes "basic" question:

i have table of customers:

table 'customers'  id primary key name varchar 250 email varchar 1000 is_active enum 'n','y' 

in script need select customers active (is_active == 'y') , send them thank email. there business class associated above table called class customers.

i can write simple without using oop:

$result = mysql_query("select * customers is_active = 'y'"); while($arr = mysql_fetch_assoc($result))  send customer thank email... 

if use oop, how do simple above? if there thousands of customers, write oo code loads thousands of customer objects send each 1 email below?

$result = mysql_query("select * customers is_active = 'y'); while($arr = mysql_fetch_assoc($result))  $objcustomer = new customer($arr['id']);   //reload has been read db??  $objcustomer->sendthankyouemail(); 

am doing wrong (or silly) above?

i wouldn't reload db rather array:

$objcustomer = new customer($arr); $objcustomer->sendthankyouemail(); 

in customer object load data array.

another way do following (object properties should match field names):

while($objcustomer = mysql_fetch_object($result, 'customer')) {     $objcustomer->sendthankyouemail(); } 

note: if new developing should using parametrized queries using mysqli or pdo.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -