connect. Connecting to a database

^connect[connect string]{code}

Operator
connect establishes connection to DB server. The code of the operator is processed by Parser within current connection.

When used as a module to Apache or IIS) Parser caches connections to SQL-servers. In case a script attempts a connection with the same connect string twice, Parser doesn't connect to SQL-server but takes result of SQL-connection from cache, if connection is still valid.

CGI-version also caches connections, but for a single http request only. That is why you can certainly use such constructions as:

^connect[connect string]{…first SQL query…}
^connect[
connect string]{…second SQL query…}

There will not be two SQL connections. It is especially useful when a connection is needed only sometimes and you cannot be sure you will always need it. In this case you may avoid doing it beforehand by doing it visually multiple times and be sure that the connection will not be broken.

We use the following methods and constructors to perform SQL-query:

table::sql
string:sql
void:sql
hash::sql
int:sql
double:sql
file::sql

Note: to work with operator
connect, you need to have an appropriately configured driver (see Configuration).   

Formats of connect string to be used with supported DB servers are described in appendix.

Example

^connect[mysql://admin:pwd@localhost/p3test]{
   $news[^
table::sql{select * from news}]
}



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 20.09.2007