database.cursor()

NES2+Syntax

							database.cursor(sql)
database.cursor(sql, boolean)

Description

The cursor() method of the database object creates a Cursor object that can be used to run SQL queries against the database. The method takes the SQL statement as a parameter, as well as an optional Boolean value that specifies if the cursor is updateable.

Example

Listing 8.42 shows how you would run a query against the database using the cursor() method. The while loop is used to write the results to the user's page.

Listing 8.42 Using the cursor() Method to Run Query Against the Database
 <SERVER> // Set the query to run var mySQL = myConn.cursor('SELECT name,title FROM employees'); // Iterate through the results and write them to the page. while(mySQL.next()){ ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.