<?php require 'monetdb/php_monetdb.php'; $db = monetdb_connect("sql", "localhost", $argv[1], "monetdb", "monetdb", $argv[2]) or die(monetdb_last_error()); $packet_size = 20000; $sql = 'select 1'; $sql = str_pad($sql, $packet_size, ' '); echo strlen($sql) . "\n"; $res = monetdb_query($sql); while ($row = monetdb_fetch_assoc($res)) { print_r($row); } monetdb_disconnect();
<?php /** * Connect to a database and perform a query. */ require '../lib/php_monetdb.php'; define("DB", "php_demo"); /* Establish a connection and report errors in case they occour */ $db = monetdb_connect($host = "127.0.0.1", $port = "50000", $database = DB, $username = "******", $password = "******") or trigger_error(monetdb_last_error()); /* Fire a query */ $query = "SELECT * FROM TABLES, TABLES"; $res = monetdb_query($db, monetdb_escape_string($query)) or trigger_error(monetdb_last_error()); /* Print the number of rows in the result set */ print "Rows: " . monetdb_num_rows($res) . "\n"; /* Iterate over the result set returning rows as objects */ //while ( $row = monetdb_fetch_object($res) ) //{ // print_r($row); //} /* Free the result set */ monetdb_free_result($res); /* Disconnect from the database */ if (monetdb_connected($db)) { monetdb_disconnect($db); }
#!/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"; }
require 'monetdb/php_monetdb.php'; $db = monetdb_connect("sql", "localhost", $argv[1], "monetdb", "monetdb", $argv[2]) or die(monetdb_last_error()); $res = monetdb_query('START TRANSACTION;') or die(monetdb_last_error()); while ($row = monetdb_fetch_assoc($res)) { print_r($row); } $res = monetdb_query('CREATE TABLE php_int64_dec18 (i BIGINT, d0 DECIMAL(18,0), d9 DECIMAL(18,9));') or die(monetdb_last_error()); while ($row = monetdb_fetch_assoc($res)) { print_r($row); } $res = monetdb_query('INSERT INTO php_int64_dec18 VALUES (1234567890987654321, 123456789987654321, 123456789.987654321);') or die(monetdb_last_error()); while ($row = monetdb_fetch_assoc($res)) { print_r($row); } $res = monetdb_query('SELECT * FROM php_int64_dec18;') or die(monetdb_last_error()); while ($row = monetdb_fetch_assoc($res)) { print_r($row); } $res = monetdb_query('SELECT * FROM php_int64_dec18;') or die(monetdb_last_error()); $cols = monetdb_num_fields($res); for ($i = 0; $i < $cols; $i++) { print monetdb_field_name($res, $i) . "\t"; } print "\n"; while ($row = @monetdb_fetch_row($res)) { for ($i = 0; $i < $cols; $i++) { print $row[$i] . "\t"; } print "\n"; }
/** * Generates the next id in the sequence $seq * * @param resource connection instance * @param seq sequence whose next * value we want to retrieve * @return string the ID of the last tuple inserted. FALSE if an error occurs */ function monetdb_insert_id($connection = NULL, $seq) { $num_args = func_num_args(); if ($num_args == 1) { $connection = mapi_get_current_conn(); $seq = func_get_arg(0); } if (is_string($seq)) { $query = "SELECT NEXT VALUE FOR " . monetdb_quote_ident($seq) . ""; $res = monetdb_query($connection, $query); $row = monetdb_fetch_assoc($result); return $row[$seq]; } return FALSE; }
#!/usr/bin/php <?php require 'monetdb/php_monetdb.php'; $db = monetdb_connect("sql", "localhost", $argv[1], "monetdb", "monetdb", $argv[2]); $tables = monetdb_query('SELECT name FROM tables'); for ($i = 0; $line = @monetdb_fetch_assoc($tables); $i++) { print $line['name'] . "\n"; } $result = monetdb_query('SELECT * FROM tables'); $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"; }
<?php error_reporting(E_ALL); require 'php_monetdb.php'; define("DB", "demo"); echo function_exists("monetdb_connect"); echo function_exists("monetdb_last_error"); $db = monetdb_connect("sql", "127.0.0.1", 50000, "monetdb", "monetdb", "demo"); $err = monetdb_last_error(); $query = "SELECT * FROM demo.sys.word_asos where main_word = 'skull'"; $res = monetdb_query($db, $query) or trigger_error(monetdb_last_error()); echo "Rows: " . monetdb_num_rows($res) . "\n"; $row = monetdb_fetch_assoc($res); var_dump($row); foreach ($row as $rows) { if ($rows != null && $rows != '') { $assoc = ""; } } monetdb_free_result($res); if (monetdb_connected($db)) { monetdb_disconnect($db); }