diff --git a/src/Adapter/Driver/Mysqli/Statement.php b/src/Adapter/Driver/Mysqli/Statement.php index 8a9a629b99..1b8f5152ef 100644 --- a/src/Adapter/Driver/Mysqli/Statement.php +++ b/src/Adapter/Driver/Mysqli/Statement.php @@ -206,7 +206,10 @@ public function prepare($sql = null) $this->resource = $this->mysqli->prepare($sql); if (!$this->resource instanceof \mysqli_stmt) { throw new Exception\InvalidQueryException( - 'Statement couldn\'t be produced with sql: ' . $sql, + sprintf( + ' Error #%d: %s. Statement couldn\'t be produced with sql: %s', + $this->mysqli->errno, $this->mysqli->error, $sql + ), null, new Exception\ErrorException($this->mysqli->error, $this->mysqli->errno) ); diff --git a/test/Adapter/Driver/Mysqli/StatementTest.php b/test/Adapter/Driver/Mysqli/StatementTest.php new file mode 100644 index 0000000000..292b8db8a2 --- /dev/null +++ b/test/Adapter/Driver/Mysqli/StatementTest.php @@ -0,0 +1,56 @@ +statement = new Statement(); + } + + public function testPrepare() + { + $this->statement->initialize(new TestAsset\MysqliMock()); + $this->assertNull($this->statement->prepare('SELECT 1')); + } + + /** + * intentionally throw exception to test error contains valid string + */ + // public function testMysqliStatementPrepareException(){ + // $this->statement = new Statement(new Connection()); + // // $this->statement->initialize(new mysqli("localhost", "test", "test", "test", 3306)); + + // // $this->_connection = mysqli_connect('localhost', 'root', ''); + // // $this->_execute('USE playpen'); + // $this->statement->setSql('SELECT * FROM test WHERE;'); + // try{ + // $this->statement->prepare(); + // // } catch (InvalidQueryException $e){ + // } catch (Exception $e){ + // fwrite(STDOUT, $e->getMessage()); + // } + // // fwrite(STDOUT, $this->statement->getSql()); + // } +} \ No newline at end of file diff --git a/test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php b/test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php new file mode 100644 index 0000000000..946f59e9ea --- /dev/null +++ b/test/Adapter/Driver/Mysqli/TestAsset/MysqliMock.php @@ -0,0 +1,23 @@ +prepare so line 206 in Statement.php throws the correct exception + // $this->resource = $this->mysqli->prepare($sql); + parent::__construct(); + } +} \ No newline at end of file