Example #1
0
<?php

/*
 * This example shows how database commands can be executed.
 * Documentation: http://basex.org/api
 *
 * (C) BaseX Team 2005-11, ISC License
 */
include "BaseXClient.php";
try {
    // initialize timer
    $start = microtime(true);
    // create session
    $session = new Session("localhost", 1984, "admin", "admin");
    // perform command and print returned string
    print $session->execute("xquery 1 to 10");
    // close session
    $session->close();
    // print time needed
    $time = (microtime(true) - $start) * 1000;
    print "\n{$time} ms\n";
} catch (Exception $e) {
    // print exception
    print $e->getMessage();
}
Example #2
0
<?php

/*
 * This example shows how new documents can be added.
 *
 * Documentation: http://docs.basex.org/wiki/Clients
 *
 * (C) BaseX Team 2005-12, BSD License
 */
include "BaseXClient.php";
try {
    // create session
    $session = new Session("localhost", 1984, "admin", "admin");
    // create new database
    $session->execute("create db database");
    print $session->info();
    // add document
    $session->add("world/World.xml", "<x>Hello World!</x>");
    print "<br/>" . $session->info();
    // add document
    $session->add("Universe.xml", "<x>Hello Universe!</x>");
    print "<br/>" . $session->info();
    // run query on database
    print "<br/>" . $session->execute("xquery /");
    // drop database
    $session->execute("drop db database");
    // close session
    $session->close();
} catch (Exception $e) {
    // print exception
    print $e->getMessage();
Example #3
0
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Create database</title>

</head>

<body>
    <?php 
include "BaseXClient.php";
//lancement de la session
$session = new Session("localhost", 1984, "admin", "admin");
//creation de la base de données
$session->execute('create db mdsiDatabase');
//ajout des fichiers
$session->execute("add ../MDSI_Database/");
// close session
$session->close();
echo '<script language="javascript"> document.location.replace("rapports.html"); </script>';
?>
</body>

</html>
Example #4
0
if (!isset($_GET['page'])) {
    exit_error('Référence manquante', 'Référence de page manquante (le paramètre "page" n\'a pas été transmis en GET).');
}
$PAGE = $_GET['page'];
// Fichier d'informations sur l'hébergement (requis avant la gestion de la session).
if (is_file(CHEMIN_FICHIER_CONFIG_INSTALL)) {
    require CHEMIN_FICHIER_CONFIG_INSTALL;
} elseif ($PAGE != 'public_installation') {
    exit_error('Informations hébergement manquantes', 'Les informations relatives à l\'hébergeur n\'ont pas été trouvées.<br />C\'est probablement votre première installation de SACoche, ou bien le fichier "' . FileSystem::fin_chemin(CHEMIN_FICHIER_CONFIG_INSTALL) . '" a été supprimé.<br />Cliquer sur le lien ci-dessous.', 'install');
}
// Le fait de lister les droits d'accès de chaque page empêche de surcroit l'exploitation d'une vulnérabilité "include PHP" (http://www.certa.ssi.gouv.fr/site/CERTA-2003-ALE-003/).
if (!Session::verif_droit_acces($PAGE)) {
    exit_error('Droits manquants', 'Droits de la page "' . $PAGE . '" manquants.<br />Soit le paramètre "page" transmis en GET est incorrect, soit les droits de cette page n\'ont pas été attribués dans le fichier "' . FileSystem::fin_chemin(CHEMIN_DOSSIER_INCLUDE . 'tableau_droits.php') . '".');
}
// Ouverture de la session et gestion des droits d'accès
Session::execute();
// Infos DEBUG dans FirePHP
if (DEBUG > 3) {
    afficher_infos_debug_FirePHP();
}
// Arrêt s'il fallait seulement mettre la session à jour (la session d'un user connecté n'a pas été perdue si on arrive jusqu'ici)
if ($PAGE == 'conserver_session_active') {
    exit('ok');
}
// Arrêt s'il fallait seulement fermer la session
if ($PAGE == 'fermer_session') {
    Session::close();
    exit('ok');
}
// Traductions
if ($_SESSION['USER_PROFIL_TYPE'] != 'public') {
Example #5
0
/*
 * This example shows how database commands can be executed 
 * and the result of a query can be processed in a dom document.
 * Documentation: http://basex.org/api
 *
 * (C) BaseX Team 2005-11, ISC License
 */
include "BaseXClient.php";
try {
    // initialize timer
    $start = microtime(true);
    // create session
    $session = new Session("localhost", 1984, "admin", "admin");
    // dom document
    $dom = new DOMDocument();
    $session->execute("create db database <root><user>\r\n  <username>Username1</username><password>Password1</password>\r\n  </user><user><username>Username2</username><password>Password2</password></user></root>");
    // perform command and print returned string
    $dom->loadXML($session->execute("xquery ."));
    // print nodes info
    getNodesInfo($dom->firstChild);
    // close session
    $session->close();
    // print time needed
    $time = (microtime(true) - $start) * 1000;
    print "<br/>{$time} ms\n";
} catch (Exception $e) {
    // print exception
    print $e->getMessage();
}
// print info of node and subnodes
function getNodesInfo($node)
 /**
  * Insert a key/value into the table. If the key, value, or timestamp
  * is null it will not be added to the execution options for the statement.
  *
  * NOTE: For batch statement the key and value should be null.
  *
  * @param Session $session Session to use when executing statement
  * @param Statement $statement Statement to execute
  * @param int $key Key to insert value into (default: null)
  * @param int $value Value being set (default: null)
  * @param mixed $timestamp Timestamp to set in execution options
  *                         (default: null)
  */
 private function insert(Session $session, Statement $statement, $key = null, $value = null, $timestamp = null)
 {
     // Create the parameters that make up the execution options
     $parameters = array();
     // Determine if the key and/or value should be added as arguments
     if (isset($key) || isset($value)) {
         // Create the arguments array for the parameters
         $arguments = array();
         if (isset($key)) {
             $arguments["key"] = $key;
         }
         if (isset($value)) {
             $arguments["value_int"] = $value;
         }
         // Assign the arguments to the parameters
         $parameters["arguments"] = $arguments;
     }
     // Determine if the timestamp should be added
     if (isset($timestamp)) {
         $parameters["timestamp"] = $timestamp;
     }
     // Insert values into the table
     $options = new ExecutionOptions($parameters);
     $session->execute($statement, $options);
 }
Example #7
0
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Create database</title>

</head>

<body>
    <?php 
include "BaseXClient.php";
$session = new Session("localhost", 1984, "admin", "admin");
$session->execute('drop db mdsiDatabase');
// close session
$session->close();
echo '<script language="javascript"> document.location.replace("index.html"); </script>';
?>
</body>

</html>