Use doctrine/dbal in place of Zend_Db

This commit is contained in:
Michael RICOIS 2016-10-03 11:25:12 +02:00
parent 13086b7d75
commit 42f2251fb5

View File

@ -58,7 +58,8 @@ class RefController extends Zend_Controller_Action
*/
public function tableAction()
{
$requetesql = $this->_getParam('q','');
$request = $this->getRequest();
$requetesql = $request->getParam('q','');
$fichierCsv = $requetesql.'.csv';
$fichierSql = $requetesql.'.sql';
@ -69,20 +70,22 @@ class RefController extends Zend_Controller_Action
if (!empty($requetesql)) {
if (!file_exists($path . $fichierCsv)) {
if (file_exists('assets/sql/'.$fichierSql)) {
//Connexion mysql
$sql = file_get_contents('assets/sql/'.$fichierSql);
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$rows = $db->fetchAll($sql);
if (count($rows) > 0) {
$headers = array_keys($rows[0]);
$csv = Writer::createFromPath($path . $fichierCsv.'.tmp', 'w');
$csv->setNewline("\r\n");
$csv->insertOne($headers);
foreach($rows as $fields) {
$csv->insertOne($fields);
}
rename($path . $fichierCsv.'.tmp', $path . $fichierCsv);
}
/**
* @var \Doctrine\DBAL\Connection $conn
*/
$conn = Zend_Registry::get('doctrine');
$sql = file_get_contents('assets/sql/'.$fichierSql);
$stmt = $conn->prepare($sql);
$stmt->setFetchMode(\PDO::FETCH_ASSOC);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$csv = Writer::createFromPath($path . $fichierCsv.'.tmp', 'w');
$csv->setNewline("\r\n");
$headers = array_keys($stmt->fetch());
$csv->insertOne($headers);
$csv->insertAll($stmt);
}
rename($path . $fichierCsv.'.tmp', $path . $fichierCsv);
}
}