laravel/laravel — Issue #121: Untrimmed query causes unexpected behaviour
Author: lomboo
Created: 2011-10-17 14:15:25+00:00
State: open

I am using Laravel version 1.5.9 and had to run some raw SQL via the ```System\DB\Connection::query``` method.

On system/db/connection.php:82 we have the following code segment of the ```query``` method.

```
if (strpos(strtoupper($sql), 'SELECT') === 0)
{
return $query->fetchAll(\PDO::FETCH_CLASS, 'stdClass');
}
elseif (strpos(strtoupper($sql), 'UPDATE') === 0 or strpos(strtoupper($sql), 'DELETE') === 0)
{
return $query->rowCount();
}
```

As strpos checks for === 0 the following queries will not enter the if blocks.

```
$sql = " SELECT * from table";
$sql = "

SELECT * from table

";
```

I think this should be fixed as people often rely on whitespaces, tabs and line-breaks to make the queries more readable.