Re: Help on objects

From: Date: Thu, 05 Oct 2006 05:04:28 +0000
Subject: Re: Help on objects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-242636@lists.php.net to get a copy of this message
I've seen you already had a good answer on the errors in the code so I won't go on that. As for OOP, the one design error you have is that you are asking for an action, not an object. You want to make SQL inserts, that is your purpose, and that is an action, which is solved by a statement, not by an object. There is no doer. Objects are what even your English teacher would call objects while describing a sentence. You are asking for a verb, you don't have a subject, you don't have an object. Of course you can wrap an action in a class, but that is bad design. Classes will usually have names representing nouns, methods will be verbs, properties adjectives, more or less, that's OOP for English teachers. Satyam ----- Original Message ----- From: "Deckard" <ml@wordlife.eu> To: <php-general@lists.php.net> Sent: Thursday, October 05, 2006 3:47 AM Subject: [PHP] Help on objects
Hi, I'm trying to lay my hands on PHP OOP, but it's not easy :( I've read several examples in the web, but cannot transpose to may case. I'm trying to set a class to make SQL inserts in mysql. I have the class: --------------------------------------------------------- <?php class dBInsert { // global variables var $first; // constructor function dBInsert($table, $sql) { $this->table = $table; $this->sql = $sql; return(TRUE); } // function that constructs the sql and inserts it into the database function InsertDB($sql) { print($sql); // connect to MySQL $conn->debug=1; $conn = &ADONewConnection('mysql'); $conn->PConnect('localhost', 'deckard', 'ble', 'wordlife'); if ($conn->Execute($sql) === false) print 'error inserting: '.$conn->ErrorMsg().'<BR>'; return (TRUE); } } -------------------------------------------------------------------- and the code that calls it: -------------------------------------------------------------------- <?php include_once("classes/dBInsert.php"); $sql = "INSERT INTO wl_admins VALUES ('',2)"; $dBInsert = new dBInsert('wl_admins', '$sql'); $dBInsert->InsertDB('$sql'); ?> -------------------------------------------------------------------- but it's not working ? Can anyone give me a hand here ? I've read the manuals, examples, etc. Any help would be appreciated. Best Regards, Deckard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#242636) next »