sconemad

technology, scones, nonsense

Loading...

Profiles

Twitter

GitHub

Launchpad

Subscribe to my RSS Feed

Admin

mysql

The mysql module provides an interface to MySQL databases.

MySQL

The mysql module supports MySQL, and uses its prepared statement API. This allows SQL queries with parameters to be constructed safely without the risk of SQL injection vulnerabilities.

Sconescript Interface

In addition to the standard module interface, it also has the following:

Properties

Name Type Descripion
profile-name Profile object Access mysql profile object by name

Methods

add ( name : String, database : String, username : String, password : String) [Admin]
Adds a database access profile with the specified name.
The datbase argument can be simply a database name, if it resides on the local machine, or a string in the form "host:database" or "host:port:database" if it is remote.
The username and password strings are used to login to the database.

Example

[In config file]
# Setup database connection profile
mysql.add("myprofile","database","username","password");

In this example the database contains a table called websites, which contains some website links.

[In sconesite script]
# Create a query that will select website details for a given category
ref query = mysql.myprofile.Query("SELECT name,url FROM websites WHERE category = ?"); # Use this to get all news sites
query.exec("News"); # Fetch and print out each result
while (query.next_result()) { ref result = query.result; print(result.name + " : " + result.url + "\n"); }
Updated on 2013-11-04 14:23:21 +0000 | Requested on 2021-05-12 16:30:34 +0000