Archive for the ‘ Propel ’ Category

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
Author : beriba | 08/17/2012

Sometimes when you’re building Criteria object you want to know what exactly Propel will produce. To be sure about the query or to debug it. You can do it as simple as that:

$params = array();
$sql = BasePeer::createSelectSql($criteria, $params);
var_dump($sql); //SQL query
var_dump($params); //array of params passed to SQL