Method queryValue
Executes query and returns the first value in the first row.
string $suSQL->queryValue(string query) string $suSQL->cache->queryValue(string query)
|
queryValue() sends a query to the currently active database on the server and returns the first value in
the first row or FALSE if no records were selected. You can cache query results by calling queryValue() method via
the cache class. The next time your block executes the same query SiteSupra will bring back results from the cache
instead of hitting the database. Refer to Using Cache for more information about SiteSupra cache.
Examples
The folowing query affects one row.
<? $query = "SELECT title FROM test WHERE id = 5"; $data = $suSQL->queryValue($query); echo "Query result: " . $data; ?>
|
The folowing query affects nine rows, but the function returns only the value in the first row "a".
<? $query = "SELECT title FROM test ORDER BY id"; $data = $suSQL->queryValue($query); echo "Query result: " . $data; ?>
|
The folowing query affects nine rows, but the function returns only the first value in the first row.
<? $query = "SELECT * FROM test ORDER BY id"; $data = $suSQL->queryValue($query); echo "Query result: " . $data; ?>
|
The folowing script shows how to check the query result in a proper way. In the example below the function returns 0, but not FALSE.
<? $query = "SELECT parent FROM test WHERE id = 1"; $data = $suSQL->queryValue($query); if($data !== FALSE) echo "Query result: " . $data; else echo "No records were selected." ?>
|