CC-4345: Prepared statements - part 1

-modified Datatables.php to use Application_Common_Database::prepareAndExecute()
This commit is contained in:
denise 2012-09-06 11:21:36 -04:00
parent b25ce921ee
commit 9b29f5e701
1 changed files with 2 additions and 23 deletions

View File

@ -164,35 +164,14 @@ class Application_Model_Datatables
$totalRows = $r->fetchColumn(0); $totalRows = $r->fetchColumn(0);
if (isset($sqlTotalDisplayRows)) { if (isset($sqlTotalDisplayRows)) {
$stmt = $con->prepare($sqlTotalDisplayRows); $totalDisplayRows = Application_Common_Database::prepareAndExecute($sqlTotalDisplayRows, $params, 'column');
foreach($params as $param=>&$value) {
$stmt->bindParam(":$param", $value);
}
if ($stmt->execute()) {
$totalDisplayRows = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
} else { } else {
$totalDisplayRows = $totalRows; $totalDisplayRows = $totalRows;
} }
//TODO //TODO
if ($needToBind) { if ($needToBind) {
$stmt = $con->prepare($sql); $results = Application_Common_Database::prepareAndExecute($sql, $params);
foreach($params as $param=>&$value) {
$stmt->bindParam(":$param", $value);
}
if ($stmt->execute()) {
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$results = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
} else { } else {
$stmt = $con->query($sql); $stmt = $con->query($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC); $stmt->setFetchMode(PDO::FETCH_ASSOC);