include file help/ pdo / stored procedures
Posted: Mon May 21, 2007 8:49 am
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
news_get.inc.php
called from
index.php
when i comment out include_once('news_list.inc.php'); it runs include_once('news_get.inc.php'); fine and vice versa.
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);
?>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);
?>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;
}
?>