Procedural to OOP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am rewriting a project, and have decided to use/learn OOP. I am
using ADODB to connect to a MS SQL 2000 box. This code works, but I'd
like to know if I'm following good form or if I'm totally missing the
boat. I'd also like to include things like the
dbhost/username/password, etc in a seperate config file would I...

class foo{

function bar(){
include('my_config_file_here.php');// sets $dbhost etc...

var $db_host = $dbhost;
...
}
}

...or is there another way.

Here is my class and my index.php which will present it. I looked at
Smarty, but I think my head would explode trying to link
ADODB-OOP-SMARTY. Little of this is original, mostly borrowed from
what OOP tutorials and code I browsed at phpclasses.org, but I
understand what it's doing, which is important.


//class.php--------------------------------------------------------------------------------------------------------
include('../adodb/adodb.inc.php');

class PO {

    var $db;
    
function Conn(){
$this->db = ADONewConnection("mssql");
$this->db->debug = false;
$this->db->Connect("MYSERVER","MYUSER","MYPASS","MYDB");
}

function PartList(){
$this->Conn();
$s = "SELECT partnumber FROM part_master ORDER BY partnumber\n";
$rs = $this->db->Execute($s);
$list = array();
while(!$rs->EOF){
array_push($list,$rs->fields[0]);
$rs->MoveNext();
}
return $list;
}

}
//class.php--------------------------------------------------------------------------------------------------------



//index.php--------------------------------------------------------------------------------------------------------
include('poman/class.php');

$po = new PO;



$parts = $po->PartList();

echo "<select name=\"frm_partnum\">\n";
foreach($parts AS $part){
echo "<option>$part</option>\n";
}
echo "</select>\n";
//index.php--------------------------------------------------------------------------------------------------------

Any suggestions or I do I have the general idea?

TIA

Mike Smith

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux