Difference between revisions of "Query Mode"
Jump to navigation
Jump to search
Line 17: | Line 17: | ||
#Close the query with <code>close()</code>. | #Close the query with <code>close()</code>. | ||
− | == | + | ==Example in [https://svn.uni-konstanz.de/dbis/basex/trunk/api/etc/php/ PHP]== |
− | |||
<pre class="brush:python"> | <pre class="brush:python"> |
Revision as of 13:26, 10 January 2011
In the query mode a query can be send to the server and executed
in an iterative manner. For this you have to call the query()
function
of the Session
with your defined query. This will return a query object
which comes with an forward-only iterator to get each result of the query.
Furthermore it is possible to bind variables to the query using the bind()
function
of the query object.
Usage
The query execution works as follows:
- Create a new session instance with hostname, port, username and password.
- Call the
query()
function of the session with the query as argument to get your query object. - Optionally bind variables to the query with the
bind()
function. - Initialize query output via
init()
. - Iterate through the query object with the
more()
andnext()
functions. If an error occurs, an exception is thrown. - Close the query with
close()
.
Example in PHP
import BaseXClient, time try: # initialize timer start = time.clock() # create session session = BaseXClient.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 = (time.clock() - start) * 1000 print time, "ms." except IOError as e: # print exception print e
for more examples see the languages section.