Beruflich Dokumente
Kultur Dokumente
1 of 10
Import your PHP applications to the Etelos™ platform
Etelos™ lets you work in the development environment of your choice. Building apps with Etelos™ is
easy – write the application it in your development environment, move it to the Etelos™ framework, and
it’s done. Once there, it can integrate with other applications, enable AppSync™ rules, work offline using
Apps On a Plane™, and share information with other Etelos™ applications. It’s up to you.
This tutorial gives instructions on how to import your PHP application to the Etelos™ environment.
Etelos™ supports the MySQL and PostgreSQL database systems. However, in order to access your
app’s database in the Etelos framework, you need to add code to your application that helps establish
database credentials.
By following these steps, you’ll get your database-driven PHP applications up and running on the Etelos
Platform.
Prerequisites
You need to make sure you have the following conditions met with your PHP application
before using it in the Etelos™ platform.
Your preferred PHP authoring tools, and any other PHP utilities that you use to
build your PHP applications. Or, log into the Etelos™ Application Management
Interface in your Etelos™ Developer account.
Once you’ve got a dump file of your MySQL database or your PostgreSQL database, you need to
create the database in your Etelos server account.
NOTE: If you do not have the ability to perform a dump of your MySQL or PostgreSQL database
to the Etelos platform, you will have problems packaging your source code for release
and sale on the Etelos Marketplace.
Download the Etelos™ PHP Helper File (etelos_ini_reader.php) to your development environment,
and put the Etelos™ PHP Helper File into your Etelos account. (For a quick video demonstration of
how to use WebDAV to log into your Etelos account server, visit
http://www.etelos.com/videos/training/webdav/webdav.html). If you need a copy of the Etelos™ PHP
Helper File, download it from the Etelos Marketplace.
To test the etelos_ini_reader.php code, locate the ini_example file. Place the ini_example file in
the same directory as your etelos_ini_reader.php file.
You should be able to see the error in the body of the page.
If you show an error, reload the file to your WebDAV environment, or refresh the page.
If you continue to see the error, contact Etelos Developer support at:
V6.Developer.Support@etelos-inc.com.
In all of the applicable database credential areas, add the following code sample to your application.
Make sure you add it to all the applicable database credential areas. It’s permittable to remove the
commented sections prior to implementation.
<?php
// These variables will store the database data or the error message.
$data = false;
$errorMessage = false;
// Include the helper class
require_once("etelos_ini_reader.php");
// Try to read the data
try{
// Try to load the INI data
$reader = new etelos_ini_reader();
$data = $reader->getData();
$errorMessage = false;
// If no exception was thrown by this point, the helper file worked.
}catch(Exception $e){
// An exception was thrown, there was a problem reading the INI file.
$errorMessage = $e->getMessage();
$data = false;
}
/**
* At this point we either have the INI data, or an error. How you deal with the
* error is up to you. The $data array should be associative with the
* following keys:
*
* dbtype Generally either "postgresql" or "mysql"
* dbhost Hostname of database server
* dbname Name of the database
* dbport TCP/IP port number, may be blank for default or N/A
* dbuser Username
* dbpass Password
*
*/
?>
Once you’ve added this code to all of the database credential areas, save and upload your PHP
Now, make sure that your PHP application works with the Etelos™ framework.
Load your application, and make sure that the code stores and retrieves information from your database
as intended. Check to make sure that your program can connect to the database from the Etelos™
framework, and that your database has information available to call.
Make sure that your database has information in it (database entries). There will be an error code
returned if the PHP code calls an empty database. If you do not have database entries, perform a
dump of your database information from either PostgreSQL or MySQL using the included dump
utilities.
Make sure that you have the etelos_helper_ini.php file installed and enabled in the correct
directory with your PHP files.
Make sure that the called database is functional and has uncorrupted information.
If you run into any trouble importing your PHP files into the Etelos™ Development Environment,
check out the Etelos™ Developer resources at www.etelos.com/developer for articles, videos,
how-tos, discussion forums, and more. Or email the Etelos™ Developer Support Team at
V6.Developer.Support@etelos-inc.com.
The following code sample enables your PHP application in the Etelos™ environment. If
needed, you may create a new PHP file with etelos_ini_helper.php from the following
code sample.
<?php
/**
* This class is meant to help developers make their application portable on the Etelos™ platform. It makes it easy to access data
from the account_info.ini file.up
* Copyright 2008 Etelos™ Inc. Reuse and modification is granted only for the purposes of developing applications on the Etelos™
platform.
*/
class etelos_ini_reader{
const FILENAME = "account_info.ini";
protected $path;
protected $ini_data;
protected $section;
/**
* Creates a new reader.
*
* @throws Exception if unable to find or parse the INI file
*/
public function __construct(){
if(!isset($_SERVER['SERVER_NAME'])){
throw(new Exception("Error: Server name not set, cannot load per-app data"));
}
$this->path = $this->findFile();
if(!$this->path){
throw(new Exception("Error: Unable to find file: ".self::FILENAME));
}
$this->ini_data = $this->loadData();
if($this->ini_data == false){
throw(new Exception("Error: Unable to read or parse: ".$this->path));
}
if(function_exists("mb_strtolower")){
$this->section = "vhost:".mb_strtolower($_SERVER['SERVER_NAME']);
}else{
$this->section = "vhost:".strtolower($_SERVER['SERVER_NAME']);
}
if(!array_key_exists($this->section,$this->ini_data)){
throw(new Exception("Error: The INI file has no entry for the current vhost
(".$_SERVER['SERVER_NAME'].")") );
}