Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : dbx Functions : dbx_query

dbx_query

Send a query and fetch all results (if any) (PHP 4 >= 4.0.6, PHP 5 <= 5.0.5, PECL dbx:1.1.0)
mixed dbx_query ( object link_identifier, string sql_statement [, int flags] )

Example 493. lists each field's name and type

<?php
$result
= dbx_query($link, 'SELECT id FROM table',
                   
DBX_RESULT_INDEX | DBX_RESULT_INFO);

for (
$i = 0; $i < $result->cols; $i++ ) {
   echo
$result->info['name'][$i] . "\n";
   echo
$result->info['type'][$i] . "\n";  
}
?>

Example 494. outputs the content of data property into HTML table

<?php
$result
= dbx_query($link, 'SELECT id, parentid, description FROM table');

echo
"<table>\n";
foreach (
$result->data as $row) {
   echo
"<tr>\n";
   foreach (
$row as $field) {
       echo
"<td>$field</td>";
   }
   echo
"</tr>\n";
}
echo
"</table>\n";
?>

Example 495. How to handle UNBUFFERED queries

<?php

$result
= dbx_query ($link, 'SELECT id, parentid, description FROM table', DBX_RESULT_UNBUFFERED);

echo
"<table>\n";
while (
$row = dbx_fetch_row($result)) {
   echo
"<tr>\n";
   foreach (
$row as $field) {
       echo
"<td>$field</td>";
   }
   echo
"</tr>\n";
}
echo
"</table>\n";

?>

Example 496. How to handle the returned value

<?php
$link  
= dbx_connect(DBX_ODBC, "", "db", "username", "password")
   or die(
"Could not connect");

$result = dbx_query($link, 'SELECT id, parentid, description FROM table');

if (
is_object($result) ) {
   
// ... do some stuff here, see detailed examples below ...
   // first, print out field names and types
   // then, draw a table filled with the returned field values
} else {
   exit(
"Query failed");
}

dbx_close($link);
?>

Code Examples / Notes » dbx_query

beyondmat

You can use stored procedures instead of having to specify a text string to execute, e.g.
$results = dbx_query($conn, 'sp_Test');
This executes the stored procedure sp_Test.


Change Language


Follow Navioo On Twitter
dbx_close
dbx_compare
dbx_connect
dbx_error
dbx_escape_string
dbx_fetch_row
dbx_query
dbx_sort
eXTReMe Tracker