| 1 |
lars |
1 |
<com:TContent ID="body">
|
|
|
2 |
|
|
|
3 |
<h1>Configuring the DataMapper for PHP</h1>
|
|
|
4 |
<p>The SQLMap PHP DataMapper is configured using a central XML descriptor file,
|
|
|
5 |
usually named <tt>SqlMap.config</tt>, which provides the details for your data
|
|
|
6 |
source, data maps, and other features like caching, and transactions. At
|
|
|
7 |
runtime, your application code will call a class method provided by the SQLMap
|
|
|
8 |
library to read and parse your <tt>SqlMap.config</tt> file. After parsing the
|
|
|
9 |
configuration file, a DataMapper client will be returned by SQLMap for your
|
|
|
10 |
application to use.</p>
|
|
|
11 |
|
|
|
12 |
<h2>DataMapper clients</h2>
|
|
|
13 |
<p>Currently, the SQLMap PHP DataMapper framework revolves around the
|
|
|
14 |
<tt>TSqlMapper</tt> class, which acts as a facade to the DataMapper framework API.
|
|
|
15 |
You can create a DataMapper client by instantiating an object of the
|
|
|
16 |
<tt>TSqlMapper</tt> class. An instance of the <tt>TSqlMapper</tt> class (your
|
|
|
17 |
DataMapper client) is created by reading a single configuration file. Each
|
|
|
18 |
configuration file can specify one database or data source. You can of couse
|
|
|
19 |
use multiple DataMapper clients in your application. Just create another
|
|
|
20 |
configuration file and pass the name of that file when the DataMapper client
|
|
|
21 |
is created. The configuration files might use a different account with the
|
|
|
22 |
same database, or reference different databases on different servers. You can
|
|
|
23 |
read from one client and write to another, if that's what you need to do.
|
|
|
24 |
First, let's take a look at the DataMapper configuration file.
|
|
|
25 |
|
|
|
26 |
<h1>DataMapper Configuration File (SqlMap.config)</h1>
|
|
|
27 |
<p>A sample configuration file for a PHP web application is shown below.
|
|
|
28 |
Not all configuration elements are required. See
|
|
|
29 |
<a href="?page=Manual.ConfigurationElements">DataMapper Configuration Elements</a>
|
|
|
30 |
for details of each configuration elements in a <tt>SqlMap.config</tt> file.
|
|
|
31 |
|
|
|
32 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
33 |
<?xml version="1.0" encoding="utf-8"?>
|
|
|
34 |
<sqlMapConfig>
|
|
|
35 |
<provider class="TAdodbProvider" >
|
|
|
36 |
<datasource ConnectionString="mysql://user:pass@localhost/test1" />
|
|
|
37 |
</provider>
|
|
|
38 |
<sqlMaps>
|
|
|
39 |
<sqlMap name="Account" resource="maps/Account.xml"/>
|
|
|
40 |
<sqlMap name="Order" resource="maps/Order.xml"/>
|
|
|
41 |
<sqlMap name="Category" resource="maps/Category.xml"/>
|
|
|
42 |
<sqlMap name="LineItem" resource="maps/LineItem.xml"/>
|
|
|
43 |
</sqlMaps>
|
|
|
44 |
</sqlMapConfig>
|
|
|
45 |
</com:TTextHighlighter>
|
|
|
46 |
|
|
|
47 |
</com:TContent>
|