$alias = db.Open
( "<connectionString>", "<query>")
Establishes connection with the database and executes the query with the values populated into the dynamic variables.
<connectionString> ADO connection string or ODBC DSN
<query> A valid SELECT query only
Returns a group variable.
Here, the recordset returned by $sql1 will close itself when it comes across the second Open() returned by $sql2, because the recordset returned by $sql2 is stored in the same $ret group variable.
LHS variable is necessary and compulsory for the proper functioning of all database functions. Hence, the following loop statement will generate $error variable:
It is recommended that you keep the connection string in a global variable at the beginning of the script to improve efficiency. Xtend IVR keeps a pool of connection objects and recordset objects to minimize resource usage.
display "Waiting for call"
$Provider= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Product.mdb;Persist Security Info=False"
display "Displaying records from the table"
$alias = db.Open($Provider,"SELECT * FROM Product")
while $alias.eof = FALSE
display $alias.id $alias.product $alias.productName
$alias = db.Skip()
Display "End of the table"
$alias = db.Close()
$alias = db.close()
- In the script, an ADO connection is established with the database "Product.mdb". The records are displayed by executing the Select query in Open(). The first record appropriate for the query given, is returned and stored in dynamic variables through $alias. Values in the record are accessed as $alias.id, $alias.product and $alias.productName where id, product and productName are the fields in the table "Product". To move forward and populate the next record, we use Skip(). This continues until End of file is reached.