Example #1
0
#!/usr/bin/php 

<?php 
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0.  If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2008-2015 MonetDB B.V.
?>

<?php 
require 'monetdb/php_monetdb.php';
$db = monetdb_connect("sql", "localhost", $argv[1], "monetdb", "monetdb", $argv[2]);
$tables = monetdb_query('SELECT name FROM tables LIMIT 10');
for ($i = 0; $line = @monetdb_fetch_assoc($tables); $i++) {
    print $line['name'] . "\n";
}
$result = monetdb_query('SELECT name, schema_id, query, type, system, commit_action, access, temporary FROM tables LIMIT 10');
$cols = monetdb_num_fields($result);
for ($i = 0; $i < $cols; $i++) {
    print monetdb_field_name($result, $i) . "\t";
}
print "\n";
while ($row = @monetdb_fetch_row($result)) {
    for ($i = 0; $i < $cols; $i++) {
        print $row[$i] . "\t";
    }
    print "\n";
}
Example #2
0
/**
 * Returns an associative array containing the column names as keys, and
 * column values as value.
 *
 * @param resource the query handle
 * @param int the position of the row to retrieve
 * @return array the next row in the query result as associative array or
 *         FALSE if no more rows exist
 */
function monetdb_fetch_assoc(&$hdl, $row = -1)
{
    if ($hdl["operation"] != Q_TABLE && $hdl["operation"] != Q_BLOCK) {
        return FALSE;
    }
    // first retrieve the row as an array
    $fetched_row = monetdb_fetch_row($hdl, $row);
    if ($fetched_row == FALSE) {
        return FALSE;
    }
    // now hash the array by field name
    $hashed = array();
    $i = 0;
    foreach ($hdl["header"]["fields"] as $field) {
        $field = str_replace(" ", "", $field);
        $hashed[$field] = $fetched_row[$i];
        $i++;
    }
    return $hashed;
}