Raven Manual - MySQL
Just like files, databases are storage containers for data, albeit more complex. Just like files, accessing a database requires opening a resource using a resource descriptor string (a URL in fact) of a particular format. Connect to the database:
'mysql://username:password@localhost:port/database' open as $mysql
Above, the resource descriptor string should look familiar to anyone who has used a URL to surf to a website, particularly an FTP site requiring username/password credentials. It breaks down as follows:
Once a resource handle has been opened, it may be used to execute queries and return results. Select data.
'SELECT * FROM mytable' $mysql query as $result
Determine how many rows are available.
$result selected as $selected_rows
Retrieve the next available row as a hash.
$result fetch as $row
Retrieve entire data set a row at a time.
$result each as $row $row print
Modify data.
'UPDATE mytable SET myfield = 3' $mysql query as $result
Determine how many rows were affected.
$result affected as $updated_rows
|