Page 1 of 1

include file help/ pdo / stored procedures

Posted: Mon May 21, 2007 8:49 am
by mad_phpq
Hi All! I have two Stored procedures run from two include files shown below. I cant get both of them to work together. Can you see anything wrong with them

news_list.inc.php

Code: Select all

<?php

		$sql = 'CALL news_list_proc(:public)';
		$sth = $dbh->prepare($sql);
		
		if ($dbh->errorCode()<>'00000'){
			die("Error: ".implode(': ',$dbh->errorInfo())."\n");
		}
		
		$sth->bindParam(':public', $public, PDO::PARAM_INT);
		
		$sth->execute();
		
		$news_item_list = array();
		
		$i=0;
		
		while ( $rows = $sth->fetch()) 
		{
			array_push ($news_item_list, $rows);
			
			$date_add = dateconvert($news_item_list[$i]['date_added'],2);
			$news_item_list[$i]['date_added'] = $date_add;
			
			$date_p = dateconvert($news_item_list[$i]['date_published'],2);
			$news_item_list[$i]['date_published'] = $date_p;
			
			$date_ex = dateconvert($news_item_list[$i]['date_expired'],2);
			$news_item_list[$i]['date_expired'] = $date_ex;
			
			$i++;
		}
		
		$sth->closeCursor();
		
		$smarty->assign ("news_item_list", $news_item_list);
?>
news_get.inc.php

Code: Select all

<?php

		$sql = 'CALL news_get_proc(:news_id)';
		$sth = $dbh->prepare($sql);
		
		if ($dbh->errorCode()<>'00000'){
			die("Error: ".implode(': ',$dbh->errorInfo())."\n");
		}
		
		$sth->bindParam(':news_id', $news_id, PDO::PARAM_INT);
		
		$sth->execute();
		
		$rows = null;
		$news_item = array();
		
		while ( $rows = $sth->fetch())
		{
			array_push ($news_item, $rows);
			
			$date_p = dateconvert($news_item[0]['date_published'],2);
			$news_item[0]['date_published'] = $date_p;
			
			$date_ex = dateconvert($news_item[0]['date_expired'],2);
			$news_item[0]['date_expired'] = $date_ex; 
		}
		
		$smarty->assign ("news_item", $news_item);
		
?>
called from

index.php

Code: Select all

<?php

$public = 1;
$page = $_GET['p'];
$news_id = $_GET['news_id'];



require_once('Smarty.class.php');					// load Smarty library
require_once('db.class.php');						// DB Connection

$smarty = new Smarty;

$smarty->template_dir = 'smarty/templates';
$smarty->config_dir = 'smarty/config';
$smarty->cache_dir = 'cache';
$smarty->compile_dir = 'templates_c';

//include_once('news_list.inc.php');

switch ($page)
{
	case "news_view" :
		include_once('news_get.inc.php');
		$smarty->display('news_view.tpl');
		break;
	default:
		$smarty->display('index.tpl');
		break;
}

?>
when i comment out include_once('news_list.inc.php'); it runs include_once('news_get.inc.php'); fine and vice versa.

Posted: Mon May 21, 2007 4:39 pm
by RobertGonzalez
What errors are you getting?

Posted: Tue May 22, 2007 4:15 am
by mad_phpq
i'm getting no errors. Its just not displaying the data. I have two stored procedures. One lists all the records. The other pulls the record by news_id. Both of them create an array from the record sets. Its all up there.

Posted: Tue May 22, 2007 10:25 am
by RobertGonzalez
var_dump() the resulting arrays. If they are empty then either your query is returning an empty set, the query is returning an error or is not returning anything.

Posted: Fri Jun 29, 2007 8:04 am
by mad_phpq
sorry for the delay. I got side tracked with another project. Only getting back to this.

I did var_dump on the array and i get array(0) { } for the second include file. And vice versa.

Posted: Fri Jun 29, 2007 10:29 am
by RobertGonzalez
mad_phpq wrote:I did var_dump on the array and i get array(0) { } for the second include file. And vice versa.
Everah wrote:var_dump() the resulting arrays. If they are empty then either your query is returning an empty set, the query is returning an error or is not returning anything.
I think you may have to reset the result pointer, or unset the result after each procedure call.

Posted: Mon Jul 02, 2007 3:56 am
by mad_phpq
i have set $rows = null at the end of each procedure and still have the same problem. How do i reset the result pointer?