{"id":1110,"date":"2015-05-12T17:57:30","date_gmt":"2015-05-12T22:57:30","guid":{"rendered":"http:\/\/xlinesoft.com\/blog\/?p=1110"},"modified":"2015-05-12T21:59:10","modified_gmt":"2015-05-13T02:59:10","slug":"using-dal-functions-in-projects-with-multiple-database-connections","status":"publish","type":"post","link":"https:\/\/xlinesoft.com\/blog\/2015\/05\/12\/using-dal-functions-in-projects-with-multiple-database-connections\/","title":{"rendered":"Using DAL functions in projects with multiple database connections"},"content":{"rendered":"<p>PHPRunner 8, ASPRunnerPro 9 and ASPRunner.NET 8 added an option to use multiple database connections in single project. This article explains how you can access data from multiple databases in your events.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/05\/multiconn_tables.png\" alt=\"\" title=\"multiconn_tables\" width=\"629\" height=\"391\" class=\"alignnone size-full wp-image-1125\" srcset=\"https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/05\/multiconn_tables.png 629w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/05\/multiconn_tables-300x186.png 300w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/05\/multiconn_tables-150x93.png 150w, https:\/\/xlinesoft.com\/blog\/wp-content\/uploads\/2015\/05\/multiconn_tables-400x248.png 400w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<h2>Method 1: using DAL functions<\/p>\n<h2>\n<!--more--><\/p>\n<h3>PHPRunner<\/h3>\n<p>We now have three options to refer to a table<\/p>\n<h4>1. $dal->Table(&#8220;table&#8221;)<\/h4>\n<p>finds first matching table by it&#8217;s name in all connections, starting with the primary connection. <\/p>\n<h4>2. $dal->Table(&#8220;table&#8221;,&#8221;schema&#8221;)<\/h4>\n<p>schema name helps to identify tables with identical names located in different schemas in databases like Oracle, Postgre and SQL Server.<\/p>\n<h4>3. $dal->Table(&#8220;table&#8221;,&#8221;schema&#8221;,&#8221;connection&#8221;)<\/h4>\n<p>Schema name can be left empty. Last parameter is connection name as it appears on &#8216;Datasource tables&#8217; screen.<\/p>\n<p>A complete code example:<\/p>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$table = $dal->Table(\"cars\",\"\",\"cars at localhost\");\r\n$rs = $table->QueryAll();\r\nwhile ($data = db_fetch_array($rs))\r\n{\r\necho $data[\"Make\"].\", \".$data[\"Model\"].\"<br>\";\r\n}\r\n<\/pre>\n<h3>ASPRunnerPro<\/h3>\n<p>We have 4 options to access a table object:<\/p>\n<h4>1. dal.Table(&#8220;table&#8221;)<\/h4>\n<p>finds first matching table by it&#8217;s name in all connections, starting with the primary connection. <\/p>\n<h4>2. dal.TableSchema(&#8220;table&#8221;, &#8220;schema&#8221;) <\/h4>\n<p>finds table by table name and schema name<\/p>\n<h4>3. dal.TableSchemaConn(&#8220;table&#8221;, &#8220;schema&#8221;, &#8220;connection&#8221;)<\/h4>\n<p>finds table by table name, schema name and connection name<\/p>\n<h4>4. dal.TableConn(&#8220;table&#8221;, &#8220;connection&#8221;)<\/h4>\n<p>finds table by table name and connection name<\/p>\n<p>A complete code example:<\/p>\n<pre name=\"code\" class=\"vb:nocontrols\">\r\nset data = dal.TableConn(\"carscars\", \"cars at localhost\").QueryAll()\r\nwhile not data.eof \r\n\tResponse.Write data(\"Make\") & \", \" & data(\"Model\") & \"<br>\"\r\n\tdata.MoveNext\r\nwend\r\ndata.close : set data=nothing\r\n<\/pre>\n<h3>ASPRunner.NET (C#)<\/h3>\n<p>We have three options to refer to a table<\/p>\n<h4>1. GlobalVars.dal.Table(&#8220;table&#8221;)<\/h4>\n<p>finds first matching table by it&#8217;s name in all connections, starting with the primary connection. <\/p>\n<h4>2. GlobalVars.dal.Table(&#8220;table&#8221;,&#8221;schema&#8221;)<\/h4>\n<p>schema name helps to identify tables with identical names located in different schemas in databases like Oracle, Postgre and SQL Server.<\/p>\n<h4>3. GlobalVars.dal.Table(&#8220;table&#8221;,&#8221;schema&#8221;,&#8221;connection&#8221;)<\/h4>\n<p>Schema name can be left empty. Last parameter is connection name as it appears on &#8216;Datasource tables&#8217; screen.<\/p>\n<p>A complete code example:<\/p>\n<pre name=\"code\" class=\"csharp:nocontrols\">\r\nvar rs = GlobalVars.dal.Table(\"carscars\",\"\",\"cars at localhost\").QueryAll();\r\nXVar data;\r\nwhile (data = CommonFunctions.db_fetch_array(rs))\r\n{\r\n\tMVCFunctions.Echo(String.Format(\"{0}, {1} <br>\", data[\"Make\"], data[\"Model\"]));\r\n}\r\n<\/pre>\n<h2>Method 2: using free form SQL Queries<\/h2>\n<p>Update all cars where make is &#8216;Audi&#8217; making YearOfMake equals 2002<\/p>\n<h4>PHPRunner<\/h4>\n<pre name=\"code\" class=\"php:nocontrols\">\r\n$cman->byName(\"cars at localhost\")->query(\"Update carscars set yearofmake=2002 where make='Audi'\");\r\n<\/pre>\n<h4>ASPRunnerPro<\/h4>\n<pre name=\"code\" class=\"vb:nocontrols\">\r\ncman.byName_p1(\"cars at localhost\").query_p1(\"Update carscars set yearofmake=2002 where make='Audi'\")\r\n<\/pre>\n<p><!--\n\n\n<h4>ASPRunner.NET (C#)<\/h4>\n\n\n\n\n\n<pre name=\"code\" class=\"csharp:nocontrols\">\r\n$cman->byName(\"cars at localhost\")->query(\"Update carscars set yearofmake=2002 where make='Audi'\");\r\n<\/pre>\n\n\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHPRunner 8, ASPRunnerPro 9 and ASPRunner.NET 8 added an option to use multiple database connections in single project. This article explains how you can access data from multiple databases in your events. Method 1: using DAL functions<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,10,1,4,3,8],"tags":[],"class_list":["post-1110","post","type-post","status-publish","format-standard","hentry","category-asp-net","category-news","category-php-category","category-php-code-generator","category-php-form-generator","category-tutorials"],"_links":{"self":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/comments?post=1110"}],"version-history":[{"count":25,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1110\/revisions"}],"predecessor-version":[{"id":1140,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/posts\/1110\/revisions\/1140"}],"wp:attachment":[{"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/media?parent=1110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/categories?post=1110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlinesoft.com\/blog\/wp-json\/wp\/v2\/tags?post=1110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}