Database setup    Getting-started

The library offers the ability to configure a connection string for the use of ODBC connections within your application. After that, convenient methods enable access to the database. Currently supported (means tested):

First of all open the config.asp and configure your connection string. The constant called AJAXED_CONNSTRING must be set to a valid connection string. Some are already suggested and can be used directly - just uncomment.

Don't forget to change the password, user and database within the predefined connection strings (for more connection strings check http://www.connectionstrings.com/). If your database is running on a different machine than the webserver then you need to change the server adress as well.

Accessing the database

Now you are able to access the database. Access is always performed through the Database class. ajaxed offers you an ready-to-use instance of that class called db. Before using it you need to either open the connection manually using the db.openDefault() method or let it do automatically by your pages. You can set the DBConnection property of your page to true. This opens and closes the database connection automatically.


<!--#include virtual="/ajaxed/ajaxed.asp"-->
<%
set page = new AjaxedPage
page.DBConnection = true
page.draw()

sub main()
  'getting a read-only recordset
  set RS = db.getRS("SELECT * FROM table", empty)
  'getting an updateable recordset
  set RS = db.getUnlockedRS("SELECT * FROM table", empty)
  'using parameters
  set RS = db.getRS("SELECT * FROM table WHERE id = {0}", 10)
  'getting a single value
  age = db.getScalar("SELECT MAX(age) FROM users", 0)
end sub
%>


Connecting to more databases

In order to switch to another database you need just to call the db.open() method with a connection string of your desired database. After that, all methods of the Database class are executed against the "new" connected database. The database connection is closed automatically at the end of page processing.

Alternatively you could also have created a new instance of Database and have both Databases opened in seperate variables.

More information

For more details about the different access methods refer to the API.
Another tutorial is available at here.

Posted in Getting-started 5863 days ago

Version 2.1.1 Released4194 days ago