Difference between revisions of "Standard Mode"
Jump to navigation
Jump to search
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <p>In the standard mode of the [[ | + | <p>In the standard mode of the [[Clients]], a database command can be |
sent to the server using the <code>execute()</code> function | sent to the server using the <code>execute()</code> function | ||
of the <code>Session</code>. This functions returns the whole | of the <code>Session</code>. This functions returns the whole | ||
Line 18: | Line 18: | ||
==Example in PHP== | ==Example in PHP== | ||
− | Taken from our [https://github.com/BaseXdb/basex-api/blob/master/ | + | Taken from our [https://github.com/BaseXdb/basex-api/blob/master/src/main/php/Example.php repository]: |
<pre class="brush:php"> | <pre class="brush:php"> | ||
Line 26: | Line 26: | ||
* Documentation: http://basex.org/api | * Documentation: http://basex.org/api | ||
* | * | ||
− | * (C) BaseX Team 2005- | + | * (C) BaseX Team 2005-15, BSD License |
*/ | */ | ||
include("BaseXClient.php"); | include("BaseXClient.php"); | ||
Line 53: | Line 53: | ||
?> | ?> | ||
</pre> | </pre> | ||
− | |||
− | |||
− |
Revision as of 15:53, 17 January 2016
In the standard mode of the Clients, a database command can be
sent to the server using the execute()
function
of the Session
. This functions returns the whole
result. With the info()
function, you can request some
information on your executed process. If an error occurs, an
exception with the error message will be thrown.
Usage
The standard execution works as follows:
- Create a new session instance with hostname, port, username and password.
- Call the
execute()
function of the session with the database commands as argument. - Receive the result of a successfully executed command. If an error occurs, an exception is thrown.
- Optionally, call
info()
to get some process information - Continue using the client (back to 2.), or close the session.
Example in PHP
Taken from our repository:
<?php /* * This example shows how database commands can be executed. * Documentation: http://basex.org/api * * (C) BaseX Team 2005-15, BSD 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(); } ?>