sdo.das.rel.examples.one-table.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 170 行 · 第 1/2 页

HTML
170
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>One-table examples</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sdo.das.rel.metadata.html">Specifying the metadata</a></div> <div class="next" style="text-align: right; float: right;"><a href="sdo.das.rel.examples.two-table.html">Two-table examples</a></div> <div class="up"><a href="sdo.das.rel.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="sdo.das.rel.examples.one-table" class="section">  <h2 class="title">One-table examples</h2>  <p class="para">   The following set of examples all use the Relational DAS to work with    a data graph containing just one application data object, a single    company and the data just to be found the company table. These examples    do not exercise the power of SDO or the Relational DAS and of course    the same result could be achieved more economically with direct SQL    statements but they are intended to illustrate how to work with the    Relational DAS.  </p>  <p class="para">   For this very simple scenario it would be possible to simplify the    database metadata to include just the company table - if that were done   the second and third arguments to the constructor and the column    specifier used in the query example would become optional.  </p>  <p class="para">   <div class="example">    <p><b>Example #1 Creating a data object</b></p>    <div class="example-contents"><p>     The simplest example is that of creating a single data object and      writing it to the database. In this example a single company object      is created, its name is set to &#039;Acme&#039;, and the Relational DAS is      called to write the changes to the database. The company name is      set here using the property name method. See the     <a href="sdo.examples.html" class="link">Examples</a>     section on the SDO extension for other ways of accessing the      properties of an object.    </p></div>    <div class="example-contents"><p>     Data objects can only be created when you have a data object to      start with, however. It is for that reason that the first call      to the Relational DAS here is to obtain a root object. This is      in effect how to ask for an empty data graph - the special root      object is the true root of the tree. The company data object is      then created with a call to     <b>createDataObject()</b>     on the root object. This creates the company data object and inserts      it in the graph by inserting into a multi-valued containment property      on the root object called &#039;company&#039;.    </p></div>    <div class="example-contents"><p>     When the Relational DAS is called to apply the changes a simple      insert statement &#039;INSERT INTO company (name) VALUES (&quot;Acme&quot;);&#039;      will be constructed and executed. The auto-generated primary key      will be set into the data object and the change summary will be reset,      so that it would be possible to continue working with the same data      object, modify it, and apply the newer changes a second time.    </p></div>                          <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">require_once&nbsp;</span><span style="color: #DD0000">'SDO/DAS/Relational.php'</span><span style="color: #007700">;<br />require_once&nbsp;</span><span style="color: #DD0000">'company_metadata.inc.php'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/**************************************************************<br />*&nbsp;Construct&nbsp;the&nbsp;DAS&nbsp;with&nbsp;the&nbsp;metadata<br />***************************************************************/<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SDO_DAS_Relational&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$database_metadata</span><span style="color: #007700">,</span><span style="color: #DD0000">'company'</span><span style="color: #007700">,</span><span style="color: #0000BB">$SDO_containment_metadata</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/**************************************************************<br />*&nbsp;Obtain&nbsp;a&nbsp;root&nbsp;object&nbsp;and&nbsp;create&nbsp;a&nbsp;company&nbsp;object&nbsp;underneath.<br />*&nbsp;Make&nbsp;a&nbsp;simple&nbsp;change&nbsp;to&nbsp;the&nbsp;data&nbsp;object.&nbsp;<br />***************************************************************/<br /></span><span style="color: #0000BB">$root&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$das&nbsp;&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">createRootDataObject</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$acme&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$root&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">createDataObject</span><span style="color: #007700">(</span><span style="color: #DD0000">'company'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$acme</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Acme"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/**************************************************************<br />*&nbsp;Get&nbsp;a&nbsp;database&nbsp;connection&nbsp;and&nbsp;write&nbsp;the&nbsp;object&nbsp;to&nbsp;the&nbsp;database<br />***************************************************************/<br /></span><span style="color: #0000BB">$dbh&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO_DSN</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_USER</span><span style="color: #007700">,</span><span style="color: #0000BB">DATABASE_PASSWORD</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$das&nbsp;</span><span style="color: #007700">-&gt;&nbsp;</span><span style="color: #0000BB">applyChanges</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$root</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <p class="para">   <div class="example">    <p><b>Example #2 Retrieving a data object</b></p>    <div class="example-contents"><p>     In this example a single data object is retrieved from the database      - or possibly more than one if there is more than one company      called &#039;Acme&#039;. For each company returned, the     <var class="varname">name</var>     and     <var class="varname">id</var>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?