为什么DB :: statement()不会在这个错误的查询中抛出异常?

My Query

I started off with this query. I expected it to insert a new row into foo where the column bar had a value of Foo Bar!.

However, the query would simply fail. As in, nothing would happen. No rows will be inserted into the table, yet I got neither an Exception nor a MySQL error.

DB::statement("INSERT INTO `foo` (`bar`) VALUES(':foobar')",
            [
                'foobar' => 'Foo Bar!',
            ]
);

My Mistake

After a considerable amount of time, I realize that the ' marks surrounding foobar were unnecessary. This query works as expected.

DB::statement("INSERT INTO `foo` (`bar`) VALUES(:foobar)",
            [
                'foobar' => 'Foo Bar!',
            ]
);

Not a Syntax Error

Thus, I thought that I must have made a simple Syntax error which caused my query to fail. So I decided to test that with a query that will obviously fail. However, when I tested this query, a QueryException was thrown.

DB::statement("INSERTT INTO `foo` (`bar`) VALUES(:foobar)",
            [
                'foobar' => 'Foo Bar!',
            ]
);

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERTT INTO foo (bar) VALUES(?)' at line 1 (SQL: INSERTT INTO foo (bar) VALUES(:foobar))


This is Weird

  • Since I was able to get an Exception thrown at me on a query that is obviously incorrect, it means that I did not turn off error_reporting or Exceptions by mistake.

  • This also means that my query was not a Syntax error, since I confirmed that a Syntax error throws a QueryException.

  • Yet, my query must be wrong somehow. Otherwise, I would get a row inserted as expected.

  • But despite my query being wrong, I do not get any errors to indicate that it is so. It just fails silently.


Reproducing

Code

This can be easily reproduced in routes.php. The output is bool(false). Yet, no QueryException or MySQL error is thrown.

Route::get('test', function() {
    dd(DB::statement("INSERT INTO `foo` (`bar`) VALUES(':foobar')",
            [
                'foobar' => 'Foo Bar!',
            ]
    ));
});

Table

CREATE TABLE IF NOT EXISTS `foo` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `bar` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

My Question

Why does my query fail without any error messages or exception being thrown?

If there is any additional information that I should provide, please let me know in the comments.