Login   Register  
PHP Classes
elePHPant
Icontem

File: database.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mariano Iglesias  >  Internationalization and Localization  >  database.php  >  Download  
File: database.php
Role: Example script
Content type: text/plain
Description: An example script that uses a database connection as a string source.
Class: Internationalization and Localization
Get internationalized texts from databases or XML
Author: By
Last change: Changed to use FileDataSource.
Date: 2005-07-17 22:04
Size: 1,464 bytes
 

Contents

Class file image Download
<?php

require_once(dirname(__FILE__) . '/I18N.class.php');
require_once(
dirname(__FILE__) . '/DatabaseConnection.class.php');

// Instantiate and set up the database handler class

$databaseConnection =& new DatabaseConnection();

$databaseConnection->setDbDriver('mysql');
$databaseConnection->setDbHost('localhost');
$databaseConnection->setDbUser('root');
$databaseConnection->setDbPassword('password');
$databaseConnection->setDbName('test');
$databaseConnection->setDbTablePrefix('');

$databaseConnection->open();

// Instantiate the source

$dataSource =& new DatabaseDataSource($databaseConnection);

// Do our I18N stuff

$i18n =& new I18N();

$i18n->setLanguage('en');
$i18n->setDataSource($dataSource);

$languages =& $i18n->fetchLanguages();
$container =& $i18n->fetch();
$section =& $i18n->fetch('section');
$element =& $i18n->fetch('section''element');

// Close our database connection

$databaseConnection->close();

// Print out results

echo '<b>ACTIVE LANGUAGES</b>';
echo 
'<hr />';
echo 
'<pre>';
print_r($languages);
echo 
'</pre>';
echo 
'<hr />';

echo 
'<b>CONTAINER</b>';
echo 
'<hr />';
echo 
'<pre>';
print_r($container);
echo 
'</pre>';
echo 
'<hr />';

echo 
'<b>SECTION</b>';
echo 
'<hr />';
echo 
'<pre>';
print_r($section);
echo 
'</pre>';
echo 
'<hr />';

echo 
'<b>ELEMENT</b>';
echo 
'<hr />';
echo 
'<pre>';
echo 
'<b>' $element '</b>';
echo 
'</pre>';
echo 
'<hr />';

?>