Changes

Jump to navigation Jump to search
144 bytes removed ,  14:20, 27 February 2020
no edit summary
<p>In the The query mode of the [[Language Bindings|bindingsClients]], allows you to bind external variables to a query can be sent to and evaluate the server andexecuted query in an iterative manner. For this, you need to call the The <code>query()</code> functionof the <code>Session</code> with your defined query. This will return a query object,which comes with instance returns a forward-only iterator to get each result of the query.Furthermore, variables can be bound to the query using the <code>bind()</code> functionof the new query objectinstance.</p>
==Usage==
<p>The query execution works as follows:</p>
#Create a new session instance with hostname, port, username and password.#Call the <code>query()</code> function of the session with the query as argument your XQuery expression to get your a query object.#Optionally bind variables to the query with one of the <code>bind()</code> functionfunctions.#Initialize query output Optionally bind a value to the context item via <code>initcontext()</code>.#Iterate through the query object with the <code>more()</code> and <code>next()</code> functions. If # As an error occursalternative, an exception is throwncall <code>execute()</code> to get the whole result at a time.# <code>info()</code> gives you information on query evaluation.# <code>options()</code> returns the query serialization parameters.#Close Don't forget to close the query with <code>close()</code>.
==PHP Example in [https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/php/ PHP]==
Taken from our [https://github.com/BaseXdb/basex-api/blob/master/src/main/php/QueryBindExample.php repository]: <pre classsyntaxhighlight lang="brush:php">
<?php
/*
* Documentation: http://basex.org/api
*
* (C) BaseX Team 2005-1115, ISC BSD License
*/
include("BaseXClient.php");
$query->bind("$name", "number");
// initialize query print $query->init();  // loop through all resultsresult while($query->more()) { print $query->nextexecute()."\n"; }
// close query instance
print $query->close();
} catch (Exception $e) {
}
?>
</presyntaxhighlight=Changelog= ;Version 7.2
for more examples see the [[Languages* Added: {{Code|languages]] section.[[Category:Developer]][[Category:Server]][[Category:Language Bindings]]context()}} function
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu