/**
  *	Prepare SQL query.
  *	Use replica connection for SELECT queries. Use master server for others.
  *	@see RM_Db_Connection::prepare for details
  */
 public function prepare($sql, $driver_options = array())
 {
     $sql = trim($sql);
     if ($this->_log) {
         $sql_log = substr(str_replace("\n", " ", $sql), 0, 60);
     }
     if (stristr($sql, 'select') === $sql) {
         if ($this->getReplicaConnection()) {
             if ($this->_log) {
                 M('Log')->record('replica', 'slave-' . $this->getReplicaConnection()->getConnectionName(), $sql_log);
             }
             return $this->getReplicaConnection()->prepare($sql);
         }
     } else {
         if (stristr($sql, 'set') !== $sql) {
             $this->useReplica(FALSE);
         }
     }
     if ($this->_log) {
         M('Log')->record('replica', 'master-' . $this->getConnectionName(), $sql_log);
     }
     return parent::prepare($sql);
 }