我有以下的php/pdo,它调用一个mysql程序返回一个文件名,但尽管准备好的语句是正确的,并从剪切和粘贴的数据库查询返回以下内容:php pdo查询无法返回结果,尽管准备好的语句正确
DB查询/结果
> call sp_CDRbyCustomer('Wind', 'R2X', DATE(DATE_SUB(NOW(), INTERVAL 10 WEEK)), DATE(NOW()));
> +------------------------------------------------------+
> | Exported filename |
> +------------------------------------------------------+
> | '/tmp/CDR_for_Wind_20140704-20140912_1410516460.csv' |
> +------------------------------------------------------+
> 1 row in set (0.02 sec)
的PHP/PDO
应返回我们的FIL ename是:
include('db.ini');
define('DEBUG', true);
if (DEBUG) {
openlog("$iam", LOG_PID | LOG_ODELAY,LOG_LOCAL4);
syslog(LOG_INFO, "START OF DEBUG LOG.");
}
/***** connect to database using db.ini for credentials *****/
try {
$dbConn = new PDO('mysql:host='.$host.';dbname='.$db, $dbUser, $dbPass, array (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION));
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
$structure_name = "'Wind'";
$cug_uid = "'R2X'";
$num_weeks = 10;
/**** Query - export file name ****/
$sqlQuery4filename = ("
call sp_CDRbyCustomer($structure_name, $cug_uid, DATE(DATE_SUB(NOW(), INTERVAL $num_weeks WEEK)), DATE(NOW()))
");
$sqlQuery4filename = preg_replace("/\r|\n/", "", $sqlQuery4filename);
debug("01: sqlQueryfile string is '" . $sqlQuery4filename . "'");
$stmnt = $dbConn->prepare($sqlQuery4filename);
debug($stmnt);
$stmnt->execute();
$stmnt->closeCursor();
$filename = $stmnt->fetch(PDO::FETCH_ASSOC);
$filename = $filename['Exported filename'];
debug("01: filename string is '" . $filename . "'");
function debug($debug) {
if(!DEBUG) return;
print '
<div class="debug">
';
print_r($debug);
print '
</div><!-- end of debug -->
';
}
但是,我只收到一个空字符串返回。
我已经有这个工作,但在颠覆它后,我结束了错误的版本,不能再得到它的工作,任何人给我任何线索,我做错了什么。
要使结果这个更清楚,上面的sql过程调用是'cut'和'paste'从'debug($ stmnt);'的结果。然后我们运行'$ stmnt-> execute();'和'$ stmnt-> closeCursor();'但是'$ stmnt-> fetch(PDO :: FETCH_ASSOC);'返回空。 – 2014-09-12 11:19:39