The following steps detail how to prepare your database.



Similar documents
A table is a collection of related data entries and it consists of columns and rows.

Connecting to a Database Using PHP. Prof. Jim Whitehead CMPS 183, Spring 2006 May 15, 2006

CPE111 COMPUTER EXPLORATION

Application note: Connecting the to a Database

MySQL Quick Start Guide

MySQL quick start guide

Server side scripting and databases

Livezilla How to Install on Shared Hosting By: Jon Manning

Lets Get Started In this tutorial, I will be migrating a Drupal CMS using FTP. The steps should be relatively similar for any other website.

MySQL Quick Start Guide

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

PHP+MYSQL, EASYPHP INSTALLATION GUIDE

Getting Started with Dynamic Web Sites

Using Cloud Databases in the Cloud Control Panel By J.R. Arredondo

PHP MySQL vs. Unity. Introduction. The PHP side. The Unity side

Download: Server-side technologies. WAMP (Windows), MAMP (Mac),

7- PHP and MySQL queries

Installation of PHP, MariaDB, and Apache

An Newsletter Using ASP Smart Mailer and Advanced HTML Editor

Designing for Dynamic Content

This installation guide will help you install your chosen IceTheme Template with the Cloner Installer package.

SQL Injection. Blossom Hands-on exercises for computer forensics and security

Making a Website with Hoolahoop

G563 Quantitative Paleontology. SQL databases. An introduction. Department of Geological Sciences Indiana University. (c) 2012, P.

Advanced Web Security, Lab

Lesson 7 - Website Administration

Version of this tutorial: 1.06a (this tutorial will going to evolve with versions of NWNX4)

How to Re-Direct Mobile Visitors to Your Library s Mobile App

Transferring Your Hosting Account

CEFNS Web Hosting a Guide for CS212

A Brief Introduction to MySQL

Check list for web developers

Web Development on the SOEN 6011 Server

MAMP 3 User Guide! March 2014 (c) appsolute GmbH!

Installing Drupal on Your Local Computer

Benchmarking and monitoring tools

Tableau Server Trusted Authentication

CSCI110 Exercise 4: Database - MySQL

Setting Up a Development Server

NEW AND IMPROVED! INSTALLING an IRC Server (Internet Relay Chat) on your WRT54G,GS,GL Version 1.02 April 2 nd, Rusty Haddock/AE5AE

MOODLE Installation on Windows Platform

We begin with a number of definitions, and follow through to the conclusion of the installation.

Short notes on webpage programming languages

Working with forms in PHP

DIPLOMA IN WEBDEVELOPMENT

HowTo. Planning table online

Drupal + Formulize. A Step-by-Step Guide to Integrating Drupal with XOOPS/ImpressCMS, and installing and using the Formulize module

MassTransit 6.0 Enterprise Web Configuration for Macintosh OS 10.5 Server

How to Make a Working Contact Form for your Website in Dreamweaver CS3

Oracle Database 10g Express

PHP Tutorial From beginner to master

TIMETABLE ADMINISTRATOR S MANUAL

Installing buzztouch Self Hosted

5. At the Windows Component panel, select the Internet Information Services (IIS) checkbox, and then hit Next.

A REST API for Arduino & the CC3000 WiFi Chip

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

All the materials and/or graphics included in the IceThemetheme folders MUST be used ONLY with It TheCityTheme from IceTheme.com.

IT Support Tracking with Request Tracker (RT)

CREATING AND EDITING CONTENT AND BLOG POSTS WITH THE DRUPAL CKEDITOR

EMPLOYEE MANAGEMENT SYSTEM

UW WEB CONTENT MANAGEMENT SYSTEM (CASCADE SERVER)

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Introduction. Just So You Know... PCI Can Be Difficult

Tutorial básico del método AJAX con PHP y MySQL

AJ Matrix V5. Installation Manual

How To Create A Website On Atspace.Com For Free (Free) (Free Hosting) (For Free) (Freer) ( (Web) (Femalese) (Unpaid) (

Getting Started Guide. Getting Started With Linux Shared Hosting. Setting up and configuring your shared hosting account.

About This Document 3. About the Migration Process 4. Requirements and Prerequisites 5. Requirements... 5 Prerequisites... 5

SQL Injection Attack Lab

Site Store Pro. INSTALLATION GUIDE WPCartPro Wordpress Plugin Version

Getting Started with WebSite Tonight

A send-a-friend application with ASP Smart Mailer

FileMaker Server 12. Custom Web Publishing with PHP

Online shopping store

Intunex Oy Skillhive Service Description 1 / 6

Seamless Web Data Entry for SAS Applications D.J. Penix, Pinnacle Solutions, Indianapolis, IN

Setup Corporate (Microsoft Exchange) . This tutorial will walk you through the steps of setting up your corporate account.

Tableau Server Trusted Authentication

Putting Your Genealogy On-line

Newsletter Sign Up Form to Database Tutorial

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

Accessing External Databases from Mobile Applications

How to Install SMTPSwith Mailer on Centos Server/VPS

How To Create A Database Driven Website On A Computer Or Server Without A Database (Iis) Or A Password (Ict) On A Server (Iip) Or Password (Web) On An Anonymous Guestbook (Iit) On Your

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Using Internet or Windows Explorer to Upload Your Site

New Relic & JMeter - Perfect Performance Testing

Overview. How It Works

How to Setup, Install & Run a Website on your Local Computer. For WordPress - on an Offline Server - WAMP

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Hacking SecondLife by Michael Thumann

Deep analysis of a modern web site

Transcription:

Using databases in Second Life or Open Sim to enhance user experience Tom Connors, SciEthis Interactive 2012 Second Life and Open Sim each have a built in system for editing the virtual world that allows for finely crafted user experiences - namely, the Linden Scripting Language. Although this language is very useful for most functionality developers and users desire, one feature unattainable with just LSL is persistent storage. Shopkeepers wishing to monitor customer purchases, game administrators wishing to maintain a high score list, and teachers wishing to log test scores, as well as a myriad of other individuals, can benefit from using a database in conjunction with their LSL. The process of setting up and using a database is fairly straightforward, but more complex than the average LSL based system. In this tutorial, I will tell you what you need to do before setting up your database system, I will demonstrate how to set up your system, and I will point you in the right direction for further resources. We will need to use three components to bring our system to fruition: LSL script - used to interact with the avatar or virtual world. Either sends data to or receives data from (or both) a PHP webpage. PHP webpage - used to relay the information between the LSL script and the mysql database. This is necessary because LSL does not have functions for performing mysql queries. mysql database - the place where the data is stored and accessed via mysql queries: statements telling the database what to do with data. The following steps detail how to prepare your database. Acquire a web host - Find a web hosting company that offers mysql and PHP and buya site. Web hosting hub is a good option. There's many others. You just need a host that allows you to edit the code of your pages and to use mysql and PHP. Install the free software necessary for editing your code and uploading files to the server. I recommend TextWrangler for editing the code if you are using a Mac and Notepad++ if you're running Windows. For uploading your files, FileZilla is a great option for either operating system. Many web hosts will offer built in text editors that may be good enough. Create a test html page and upload it to the server to test your site. Call the page "test.html". Sample code below: <html> <body> <h1>it works!</h1> </body> </html>

Once you can see this page in your browser, you're ready to test php. Create another test page called "test.php". Sample code below: echo ("Even php works!"); Once php is established to work, it's time to set up the database. Your web host will probably make this easy for you. Look for options such as "MySQL Databases" or "phpmyadmin." Setting up the database will be different based on your web host, but the process shouldn't be complicated. Make a database. For the purpose of this tutorial, we will assume we've made a database called "Test_DB." Databases need tables to store the actual data. You must make a table within the database. Let's assume we make one called "test_table." Add whatever fields you need in the table. We'll assume we are using our database to relate point values to second life keys. This will require a "points" field and a "key" field. Now it is time to write test php code for our table. Let's look at a simple example. Let's call this one "test_read.php"!!! CODE STARTS BELOW THIS LINE!!! //set up the connection to the database //$con is a variable that holds the connection information //the connection information is obtained with the function mysql_connect //mysql_connect takes three parameters: //host of database - here is it "localhost." This will probably be the case for you as well //database user name - the name of a user permitted to access the table. //user name password - the password of that user. $con = mysql_connect("localhost","user","password"); //error checking //could be phrased "If the connection doesn't work, end this process and give an error report" if(!$con) die('could not connect: '. mysql_error()); //select which specific database we want mysql_select_db("test_db", $con);

//build the query - the command/request to give to the database $query = "SELECT * FROM test_table WHERE 1"; //run the query, store the result in a variable called $result $result = mysql_query($query); //check how many rows we got back with our query $rows_returned = mysql_num_rows($result); //if we got anything back, if($rows_returned > 0) //cycle through and print what we got. while($row = mysql_fetch_array($result)) echo $row[points]. ' '. $row[key]. '<br/>'; //close the connection mysql_close($con);!!! END PHP CODE!!! With that example, we saw how to get what is in the table. The next example will show us how to write things to the table. Let's call this one test_write.php.!!! CODE BEGINS BELOW THIS LINE!!! //first create variables to hold the data we'll write to the table. //a variable for the avatar's key. $avatar_key = '12345678-1234-1234-1234-123456789101'; //a variable for the avatar's points: $points = 90; //connect to the database $con = mysql_connect("localhost","user","password"); //error checking //could be phrased "If the connection doesn't work, end this process and give an error report" if(!$con) die('could not connect: '. mysql_error()); //select which specific database we want

mysql_select_db("test_db", $con); //build the query - the command/request to give to the database $query = "INSERT INTO test_table (test_table.key, test_table.points) VALUES ('". $avatar_key. "', '". $points. "')"; //print out the query on the screen for us to examine echo $query. '<br/>'; //run the query, store the result in a variable called $result $result = mysql_query($query); //will print 1 is success, nothing otherwise. echo ($result); //close the connection mysql_close($con);!!! END PHP CODE!!! Now we have seen how to add data to a database and how to retrieve it using php and mysql queries. Next, we have to write some lsl code. We'll start with a script that writes an avatar's key and an arbitrary point value to the database whenever the object the script is in is touched. Put this script in an object and compile it (but don't touch the object yet).!!! BEGIN LSL CODE!!! //define a string that contains the url of the php page we are going use. string writingpage = "http://www.yourwebsite.com/test_write.php"; //define a key that will contain the key of the request to send the data to the database. This is useful in error checking. key requestkey; default touch_start(integer numdetected) //define a key that contains the key of the avatar who touched the object. key toucher = lldetectedkey(0); //define an integer that contains the number of points this avatar gets. integer points = 90; //define a string to contain the body of the request. string body = ""; //define a string to contain the complete url of the request. //note that the complete url is more than just the page's address. //you need additional information for the php, explained later.

string URL = writingpage + "?" + "key=" + (string)toucher + "&points=" + (string)points; //define a list to contain the parameters of the http request. list parameters = [HTTP_METHOD, "GET"]; //send the request requestkey = llhttprequest(url, parameters, body); http_response( key request_id, integer status, list metadata, string body ) //if this is a response to the request we just sent (it probably is.) if(request_id == requestkey) //tell us what was returned. llownersay("status: " + (string)status); llownersay("body: " + body);!!! END LSL CODE!!! Let's take a look at the line: string URL = writing_page + "?" + "key=" + (string)avatarkey + "&points=" + (string)points; If we format that so that all of the variable names are replaced with their values (assuming the toucher's key is "d456c56a- 665a- 494a- 91f2- d7d8412da6fe"), we get this for the url: http://www.mywebsite.com/lsl/writetotest.php?key=d456c56a- 665a- 494a- 91f2- d7d8412da6fe&points=90 Everything up to the.php makes sense; that's just the address and page name. So what's the question mark and all that other stuff? These parts of the url after the page name are parameters to the php file. The question mark tells the browser "the stuff that follows will be php parameters." The bit that looks like key=d456c56a- 665a- 494a- 91f2- d7d8412da6fe tells the php file that it has access to a parameter named key with that value. The same thing can be seen with the points part &points=90 The ampersand just means "this is another parameter." The php file now has access to a parameter named points, set to 90. So, how do we make use of these parameters in our php? Here's an example to help:!!! BEGIN PHP CODE!!! //use the key parameter to set the $avatar_key variable $avatar_key = $_GET['key'];

//use the points parameter to set the $points variable $points = $_GET['points']; //display the results. echo $avatar_key. '<br/>'; echo $points;!!! END PHP!!! The above php uses its two parameters, key and points, to set two variables, $avatar_key and $points. We can use this in our test_write.php file. Rather than hard coding the variables that we write to the database as we did in the first example using test_write.php, we can get those variables using parameters. Update your test_write.php, save it, then touch your object. Did the object say your query, then the number one? That's good! That means your query was successful. Check your database table by reloading test_read.php to see if your data made it there. Obviously, we also need to read from the database, so let's take a look at that. The script will send an avatar key to a php page, and get back that person's number of points. We will need to modify test_read.php before this code will run properly.!!! BEGIN LSL SCRIPT!!! //define a string that contains the url of the php page we are going use. string readingpage = "http://www.yourwebsite.com/test_read.php"; //define a key that will contain the key of the request to send the data to the database. //We need this to know we're getting the right data when we receive the response. key requestkey; default touch_start(integer numdetected) //define a key that contains the key of the avatar who touched the object. key toucher = lldetectedkey(0); //define a string to contain the body of the request. string body = ""; //define a string to contain the complete url of the request. //note that the complete url is more than just the page's address. //you need additional information for the php, explained later. string URL = readingpage + "?" + "key=" + (string)toucher; //define a list to contain the parameters of the http request. list parameters = [HTTP_METHOD, "GET"]; //send the request requestkey = llhttprequest(url, parameters, body);

//this function runs when we hear back from the php page. http_response(key request_id, integer status, list metadata, string body) //check that the request_id matches our previously defined requestkey. A security measure. if(request_id == requestkey) llownersay("got back a point value of " + body);!!! END LSL SCRIPT!!! Now let's look at the slightly modified test_read.php. The three changes to note are: 1) setting $avatar_key using the 'key' parameter 2) using a different sql query with a WHERE clause 3) when checking rows returned, we don't need to loop through them we just return the first row's point value.!!! BEGIN PHP CODE!!! //get the key from the parameter $avatar_key = $_GET['key']; //set up the connection to the database $con = mysql_connect("localhost","username","password"); //error checking if(!$con) die('could not connect: '. mysql_error()); //select which specific database we want mysql_select_db("test_db", $con); //build the query - the command/request to give to the database $query = "SELECT test_table.points FROM test_table WHERE test_table.key = '". $avatar_key. "'"; //run the query, store the result in a variable called $result $result = mysql_query($query); //check how many rows we got back with our query $rows_returned = mysql_num_rows($result); //if we got anything back, if($rows_returned > 0)

$row = mysql_fetch_array($result); echo $row[points]; //close the connection mysql_close($con);!!! END PHP CODE!!! Once you've got that written and saved, go back into SL/OS and click on your object. You should get back a point value of 90. These php and lsl scripts can be endlessly modified to handle your specific database needs. There's a multitude of websites to help you write your lsl, php, and mysql queries. Here's a few I find most helpful: For an introduction to php: http://w3schools.com/php/default.asp For information about using mysql with php: http://w3schools.com/php/php_mysql_intro.asp For general lsl information: http://lslwiki.net/lslwiki/wakka.php?wakka=homepage