Author : beriba | 08/27/2012

Sometimes building query using Criteria can be very painful. And that’s a fact. There is also another thing – Propel is not as powerful as plain SQL. Sometimes you need to make very complex query to get some data from your database. If you’re in that point, consider using a view. Of course if your database supports them (PostgreSQL and MySQL does).

When view is not what you are looking for or you want to strictly write SQL query and execute it via Propel, here’s how to do this:

$sql = "SELECT * FROM table;"; //your SQL query
$conn = Propel::getConnection();
$st = $conn->prepare($sql);
$results = $st->fetchAll(PDO::FETCH_ASSOC);
//$results - associative array of results
//each element is as row
//every element is an array where keys are names of columns 
//and values are just values of these columns