Second Life Scripting – Communicating With And Storing To A SQL Database

The standard way of storing data for those who do not know how to send data to a database and then retrieve data is using the notecard. While this is fine for simplified storage, the notecard can not be written to, and the user of the item must edit the notecard to make changes. With the ability to send data to a database for storage opens up many options. The user can store visitor logs, store players names and scores from a hunt / quest, track how many items they have sold at a in-world store. Once that data has been stored, you can then read and query the database to get totals, specific tables such as names, scores.

Let’s get started shall we?

Before getting started you will first need a free web hosting provider or a paid hosting provider. Once you have a provider, and have the ability to upload a file to your host such as using FTP, you can continue with this guide. If you just wish to learn how communicating with and storing to SQL is done for future reference, this will be a great way to get you started in communicating from a prim to a server outside of Second Life.

You will need the following files before getting started. All files have been scanned and are virus free.

Communications PHP File

Second Life Communications Script

The first file you will need to COPY and PASTE into Notepad on your computer.

Once pasted you will choose SAVE AS and then choose Save As Type then save as communications.php

Upload this file your host provider using FTP or file manager.

Make sure the file is uploaded to folder called PUBLIC_HTML.

The second file will be used in Second Life. You will want to rez a cube, edit the cube, go to contents, choose New Script.

Open the New Script, REMOVE the code, and replace with the code from the Second Life Communications Script listed above.

Save your script, exit edit.

Creating Your Database:

Most hosting providers provide a CPanel, giving you access to server, allowing you to create databases, installing WordPress, setting up E-Mail and other features. Once you are logged into your CPanel, we will want to create a database.

Your screen may differ, and your database name will be different, however, the concept is the same.

Give your Database a name, then choose Create Database.

Create a user that can access your SQL Database.

Give your newly created user full rights to the Database.

This will allow the user to write to, edit and delete data.

Go back to your CPanel and choose phpMyAdmin

Once loaded, be sure to click on the name of the database you created earlier from the list.

Click on SQL.

You will now use the SQL Script to create your actual tables.

For demonstration and learning purposes, ‘quest’ will be the default name used to create our tables.

Click here to copy the SQL Table Script. Paste this script in the SQL box as pictured above.

Once you have copied then pasted, click Go to create your tables.

Click on Structure to see your newly created tables.

Let’s Start Communicating:

Before we do a full test, it is always a good idea to understand exactly what is going on.

Here is a few link that will explain how the Second Life Communications Script Works.

HTTP Request

HTTP Response

Looking at the above code, there is one section you will need to change:

Edit your prim.

Go to contents and open your script.

Replace the with your own URL.

Once changed, save your script.

We are now ready to test the script, the SQL and the communications PHP file. Drum roll please!

Touch your prim, and if all goes well you should see the following:

The next tutorial will explain how to modify and add more features. Feel free to share this post 🙂

What's Your Reaction?


More From: scripting

Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Voting to make decisions or determine opinions
Formatted Text with Embeds and Visuals
Youtube, Vimeo or Vine Embeds
Soundcloud or Mixcloud Embeds
Photo or GIF
%d bloggers like this: