Syntax to call a class' methods in your own class

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

 



What is the correct syntax for calling methods from other classes into your own class ?


Example:
Calling the ADODB class with:
$this->conn=&ADONewConnection('mysql');


This works:
$rs= $this->conn->GetAll("SELECT title FROM content WHERE page_id= ?", $id);

This fails:
while (!$rs->$this->conn->EOF)
{
// iterate through $rs
}


Can someone point me in the right direction ?
I did not want to use 'Extends' because I wanted incorporate several pre-existing classes,like ADODB, into my own class
I am more than a bit new at OOP so any help is appreciated.


Code:
<?php
require ("./adodb/adodb.inc.php");

$PageBuilder = new PageBuilder();
$PageBuilder->getPageTextbyID($id=1);

//------------------------------------------------------

class PageBuilder{

public function __construct() {
$this->connect2db('localhost','u','p','db');
}


public function __destruct() {
# Close the db connection
$this->conn->Close();
}



//---- Methods within the PageBuilder Class ---- //

private function connect2db()
{
$this->conn=&ADONewConnection('mysql');
$this->conn->Connect($server,$u,$p,$db);	
}


public function getPageTextbyID($id)
{
// this query DOES work
$rs= $this->conn->GetAll("SELECT title FROM content WHERE page_id= ?", $id);


// ---------------Now iterate through $rs----------------//

// Original Iteration Code

while (!$rs->EOF) {
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
print $result->fields[$i].' ';
$rs->MoveNext();
print "<br>\n";


//    Failed: First Attempt using $this->

while (!$rs->$this->conn->EOF)
{
for ($i=0, $max=$rs->$this->conn->FieldCount(); $i < $max; $i++)
echo "the result is:". $rs->$this->conn->fields[$i].' ';
$rs->$this->conn->MoveNext();
print "<br>\n";
}


// Failed: Second Attempt using ::

while (!$rs->conn::EOF)
{
for ($i=0, $max=$rs->conn::FieldCount(); $i < $max; $i++)
echo  $rs->conn::fields[$i].' ';
$rs->conn::MoveNext();
print "<br>\n";
}


}

--
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