Changes

Jump to navigation Jump to search
446 bytes added ,  15:53, 17 January 2016
no edit summary
<p>In the standard modeof the [[Clients]], a database command can be
sent to the server using the <code>execute()</code> function
of the <code>Session</code>. This functions returns the whole
exception with the error message will be thrown.</p>
<h2>==Usage</h2> ==
<p>The standard execution works as follows:</p>
 
# Create a new session instance with hostname, port, username and password.
# Call the <code>execute()</code> function of the session with the [[Commands|database commands]] as argument.
# Receive the result of a successfully executed command. If an error occurs, an exception is thrown.
# Optionally, call <code>info()</code> to get some process information
# Continue using the client (back to 2.), or close the session.
<ol start="1"> <li>Create a new session instance with hostname, port, username and password.</li> <li>Call the <code>execute()</code> function of the session with the <a href="commands">database command</a> as argument.</li> <li>Receive the result of a successfully executed command. As an error occurs an exception is thrown.</li> <li>Continue using the client (back to 2.), or close the session.</li> </ol> Example in PHP==
<h2>Taken from our [https://github.com/BaseXdb/basex-api/blob/master/src/main/php/Example</h2> .php repository]: <ol startpre class="1brush:php"> <li>Create a session object?php/* * This example shows how database commands can be executed. * Documentation: http:<br/> /basex.org/api * * (C) BaseX Team 2005-15, BSD License */include("BaseXClient.php"); try { // initialize timer $start = microtime(true);  // create session <code>Session $session = new Session("localhost", 1984, "admin", "admin")<; /code></li> <li>Run the perform command in question and print the textual result:<br/> returned string <code> print $session.->execute("info databasexquery 1 to 10")<;  /code></liclose session $session-> close(); <li>Close the session:<br //> print time needed $time = (microtime(true) - $start) * 1000; print "\n$time ms\n";  <code>session.close} catch (Exception $e)<{ //codeprint exception print $e-></ligetMessage();}?> </olpre>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu