Binding params with LIKE

Hello everyone.

I am implementing a LetterPagination and i found the following problem when trying to bind a parameter in a condition that uses LIKE. The code is:


<?php


class LetterPagination extends CComponent {

    

	public $pageVar = 'letter';

	public $filterColumn = 'name';

    

	/**

	 * 

	 * @param CDbCriteria $criteria

	 * @return 

	 */

	public function applyFilter($criteria) {

		$criteria->condition = "{$this->filterColumn} LIKE ':letter%'";

                $criteria->params = array(':letter' => $_GET['letter'];

		$criteria->order = "{$this->filterColumn} ASC";

	}

}


?>

there is something wrong in the code above?

YII doesn’t run the query correctly. The return is an empty set of records.

Maybe a bug on bind?

Tks!!

You should bind like the following:

… LIKE :letter

array(’:letter’=>$_GET[‘letter’].’%’)

This is required by PDO.

Also, make sure you have validated $_GET[‘letter’]

Works!!!

Thanks qiang!!!