Changes

Jump to navigation Jump to search
373 bytes removed ,  14:20, 27 February 2020
no edit summary
<p>The query mode of the [[Clients]] allows you to bind external variables to a query
and evaluate the query in an iterative manner. For this, you need to call the The <code>query()</code> functionof the <code>Session</code> instance with your defined query. This will return returns a new query object,which comes with a forward-only iterator. Variables can be bound to the query using the<code>bind()</code> function of the 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 an error occurs, an exception is thrown.# As an alternative, call <code>execute()</code> to get the whole result at a time. This will be faster in most cases, as the socket communication will be limited to a single call.# Optionally, call <code>info()</code> to get gives you information on query evaluation.# <code>options()</code> returns the number of results, query time, etcserialization parameters.# Close Don't forget to close the query with <code>close()</code>.
==PHP Example==
Taken from our [https://github.com/BaseXdb/basex-api/blob/master/etcsrc/main/php/QueryBindExample.php repository]:
<pre classsyntaxhighlight lang="brush:php">
<?php
/*
* Documentation: http://basex.org/api
*
* (C) BaseX Team 2005-1115, 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
[[Category* Added:Developer]][[Category:Server]][[Category:Clients]]{{Code|context()}} function
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu