10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Introduction to Connections 29<br />

// test.php<br />

Listing<br />

3-13<br />

// ...<br />

$conn->export->createTable('test', array('name' => array('type' =><br />

'string')));<br />

$conn->execute('INSERT INTO test (name) VALUES (?)', array('jwage'));<br />

Now lets execute a simple SELECT query from the test table we just created to make sure<br />

the data was inserted and that we can retrieve it:<br />

// test.php<br />

Listing<br />

3-14<br />

// ...<br />

$stmt = $conn->prepare('SELECT * FROM test');<br />

$stmt->execute();<br />

$results = $stmt->fetchAll();<br />

print_r($results);<br />

Execute test.php from your terminal and you should see:<br />

$ php test.php<br />

Array<br />

(<br />

[0] => Array<br />

(<br />

[name] => jwage<br />

[0] => jwage<br />

)<br />

Listing<br />

3-15<br />

)<br />

Conclusion<br />

Great! Now we learned some basic operations of <strong>Doctrine</strong> connections. We have modified our<br />

<strong>Doctrine</strong> test <strong>en</strong>vironm<strong>en</strong>t to have a new connection. This is required because the examples<br />

in the coming chapters will require a connection.<br />

Lets move on to the Configuration (page 30) chapter and learn how you can control<br />

functionality and configurations using the <strong>Doctrine</strong> attribute system.<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!