summaryrefslogtreecommitdiff
path: root/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
diff options
context:
space:
mode:
authorxue <>2007-04-05 19:53:01 +0000
committerxue <>2007-04-05 19:53:01 +0000
commit16bbf435c8048c3c726de78adc8a670b8a527229 (patch)
tree8884afb6f7d706a758ac7a6775c897e2b633d308 /demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
parent791acbbebad01a33cce22209ea561b282ee876e4 (diff)
Added Day2 for blog-tutorial.
Diffstat (limited to 'demos/blog-tutorial/protected/pages/Day2/ConnectDB.page')
-rw-r--r--demos/blog-tutorial/protected/pages/Day2/ConnectDB.page37
1 files changed, 37 insertions, 0 deletions
diff --git a/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page b/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
index 26d8a751..232ceb98 100644
--- a/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
+++ b/demos/blog-tutorial/protected/pages/Day2/ConnectDB.page
@@ -3,6 +3,43 @@
<h1>Establishing DB Connection</h1>
<p>
+To use the database that we just created, we first need to establish a connection to it.
</p>
+<p>
+We are going to use <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.DAO">Data Access Objects (DAO)</a> to abstract our data access mechanisms. If in future we decide to use a different DBMS (e.g. PostgreSQL, Oracle) to store our blog data, we only need to change the database source name (DSN) and we can keep our PHP code intact.
+</p>
+
+<com:NoteBox>
+To use DAO, you have to install and enable the <a href="http://www.php.net/manual/en/ref.pdo.php">PHP PDO extension</a> <i>and</i> a database-specific PDO driver (in our case, it is the SQLite PDO driver). This can be achieved easily on Windows by modifying the <tt>php.ini</tt> file with the following lines:
+<com:TTextHighlighter CssClass="source">
+extension=php_pdo.dll
+extension=php_pdo_sqlite.dll
+</com:TTextHighlighter>
+</com:NoteBox>
+
+<p>
+To further reduce the dependency on the actual database tables, we will also use the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.ActiveRecord">Active Record</a> feature which is based on PDO. Each data record will be represented as an Active Record object, which saves us from writing repetitive SQL statements.
+</p>
+
+<p>
+We modify our application configuration file <tt>protected/application.xml</tt> by inserting the following lines, which tells Active Record how to connect to our newly created database:
+</p>
+
+<com:TTextHighlighter CssClass="source" Language="xml">
+<modules>
+ <module class="System.Data.ActiveRecord.TActiveRecordConfig">
+ <database ConnectionString="sqlite:protected/data/blog.db" />
+ </module>
+</modules>
+</com:TTextHighlighter>
+
+<p>
+The configuration above shows that we are adding to our application a <a href="http://www.pradosoft.com/demos/quickstart/?page=Fundamentals.Modules">module</a> whose class is specified in the <a href="http://www.pradosoft.com/demos/quickstart/?page=Fundamentals.Components">namespace</a> format as <tt>System.Data.ActiveRecord.TActiveRecordConfig</tt>. Through this module, Active Record will automatically establish a DB connection by using the connection information given in <tt>ConnectionString</tt>.
+</p>
+
+<com:InfoBox>
+One may set up two or more DB connections in the application configuration. For more details, see the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.ActiveRecord">Active Record Documentation</a>. And of course, one may also explicitly create a DB connection in PHP code using the <a href="http://www.pradosoft.com/demos/quickstart/?page=Database.DAO">TDbConnection</a> component in PDO.
+</com:InfoBox>
+
</com:TContent> \ No newline at end of file