Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2008, 03:14 PM
Junior Member
 
Join Date: Apr 2008
Posts: 5
Default Real issues

Hi Folks,

I'm experiencing real issues here.

class searchAll{

function __construct($dbIn,$post){
$this->db = $dbIn;
$this->post = $post;
}

private function allowedImages($cid){
$db = $this->db;

$sub_sel = $db->select()
QUERY WORKS OK
$te = $sql->__toString();
$tf = $db->query($te); // issue has to be db??
print "$te<br>----<br>$tf<hr>";
}

public function imageSearch(){
$db = $this->db;

$search = $db->select()
QUERY WORKS CORRECT

$search = $db->query($search);

while ($row = $search->fetch())
{
$cid = $row['Company_ID'];
$tr = $this->allowedImages($cid);
print "$cid-$tr<br>";
}
}
}

$test = new searchAll($db,$_POST);
$test->imageSearch();

I can't see why the repeated calls to allowedImages don't return a new result every time $tr is called. If you comment out the tr line it will return 8 results however if you don't it only returns one result. I think its the fact that $db is repeatedly called in the allowedImages function but can't see a workaround.

Many thanks

A
p.s - upon further investigation the former ADODB works fine on a non persistent connection, so not quite sure what Zend is doing here??

Last edited by Ukuser26 : 04-09-2008 at 03:55 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 09:33 AM
Junior Member
 
Join Date: Apr 2008
Posts: 5
Default

Quote:
Originally Posted by Ukuser26 View Post
Hi Folks,

I'm experiencing real issues here.

class searchAll{

function __construct($dbIn,$post){
$this->db = $dbIn;
$this->post = $post;
}

private function allowedImages($cid){
$db = $this->db;

$sub_sel = $db->select()
QUERY WORKS OK
$te = $sql->__toString();
$tf = $db->query($te); // issue has to be db??
print "$te<br>----<br>$tf<hr>";
}

public function imageSearch(){
$db = $this->db;

$search = $db->select()
QUERY WORKS CORRECT

$search = $db->query($search);

while ($row = $search->fetch())
{
$cid = $row['Company_ID'];
$tr = $this->allowedImages($cid);
print "$cid-$tr<br>";
}
}
}

$test = new searchAll($db,$_POST);
$test->imageSearch();

I can't see why the repeated calls to allowedImages don't return a new result every time $tr is called. If you comment out the tr line it will return 8 results however if you don't it only returns one result. I think its the fact that $db is repeatedly called in the allowedImages function but can't see a workaround.

Many thanks

A
p.s - upon further investigation the former ADODB works fine on a non persistent connection, so not quite sure what Zend is doing here??
------

OK - I have some sample code to resimulate this problem:

** SQL
CREATE TABLE `test` (
`test_id` int(11) NOT NULL,
`name` text,
PRIMARY KEY (`test_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
insert into `test`(`test_id`,`name`) values (1,'test 1'),(2,'test3'),(3,'test4'),(4,'testx');

** OOP code
require_once 'Zend/Db/Adapter/Mysqli.php';

$db = new Zend_Db_Adapter_Mysqli(array(
'host' => 'localhost',
'username' => 'us',
'password' => 'pw',
'dbname' => 'db'
));

// Debugging
$db->getProfiler()->setEnabled(true);

class searchAll{

function __construct($dbIn){
$this->db = $dbIn;
}

private function allowedImages($cid){
$db = $this->db;
$sql = "Select * from test where test_id='$cid'";
return $db->fetchAll($sql);
}

public function imageSearch(){
$db = $this->db;

$search = $db->query("Select * from test");

while ($row = $search->fetch())
{
$cid = $row['test_id'];
echo print_r($this->allowedImages($cid));
echo "<hr>";
}

}
}

$test = new searchAll($db); // this should therefore output 4 rows of arrays
$test->imageSearch();
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:16 AM.