1

I have a controller where I create a table with doctrine raw sql:

$sql = 'CREATE TABLE IF NOT EXISTS testTable
(id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB';
$em = $this->getDoctrine()->getManager();

$statement = $em->getConnection()->prepare($sql);
$statement->execute();

Yet I cannot seem to figure out how to get a response to know if it executed successfully. Any ideas?

1
  • If there is a problem then an exception will be thrown. No exception means that the table was created. In other words, no need to do or check anything. Though execute does return true on success. Commented Apr 14, 2017 at 15:36

2 Answers 2

2

Cerad is correct. Get the errorCode and check if it is '0000'. I'm using MySQL and I get '0000' as an errorCode if it ran successfully.

...
$statement->execute();

var_dump( $statement->errorCode() );   // Get the error code.

I think that should work for you.

For reference I got that from the Doctrine API documentation and I tried it out. Here is the link for reference:

http://www.doctrine-project.org/api/dbal/2.4/class-Doctrine.DBAL.Driver.Statement.html

Sign up to request clarification or add additional context in comments.

Comments

1

Response should be in your "statement" variable, add a: var_dump($statement); and see.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.