Category: Other

Raven and 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:

   * mysql:// (required) specifies the database driver to use.
   * username (required).
   * password (optional).
   * localhost (required) is the hostname of the server, 
   which could be any name resolvable through DNS or /etc/hosts. 
   Hostname uses an @ symbol to    separate the hostname from the password.
   * port (optional) is the port on which the MySQL server is running.
   * database (required) is the name of the default database to use.

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


You can find more about Raven here: http://mythago.net/samples/mysql.html

Retrieved from "http://forge.mysql.com/wiki/Raven_and_MySQL"

This page has been accessed 1,602 times. This page was last modified 14:37, 9 August 2006.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...