<?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); }
<?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();
#!/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"; }
<?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); }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"" xml:lang="en" lang="en"> <head> <title>MonetDB Query</title> </head> <body> <?php require '../lib/php_monetdb.php'; if (isset($_POST['query'])) { $db = monetdb_connect($lang = "sql", $host = "127.0.0.1", $port = "50000", $username = "******", $password = "******", $database = "php_demo") or die(monetdb_last_error()); $sql = monetdb_escape_string($_POST['query']); $res = monetdb_query($sql); while ($row = monetdb_fetch_assoc($res)) { print "<pre>\n"; print_r($row); print "</pre>\n"; } monetdb_disconnect(); } print "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">\n"; print "<label for=\"query\">SQL Query:</label>\n"; print "<input type=\"text\" name=\"query\" id=\"query\"\n\tvalue=\"{$_POST['query']}\" />\n"; print "<input type=\"submit\" value=\"Execute\" />\n"; print "</form>\n"; ?>
if ($conn["socket"] != NULL) { $cmd = "auto_commit " . $flag; mapi_write($conn["socket"], format_command($cmd)); return TRUE; } return FALSE; } function err($code, $str) { http_response_code($code); header("Content-Type: text/plain"); die($str . "\r\n"); } // you should not have to change stuff below. // require 'phplib/php_monetdb.php'; $db = monetdb_connect("sql", monetdb_host, monetdb_port, monetdb_user, monetdb_pass, monetdb_dbnm); if (!$db) { err(400, "Could not connect to database: " . monetdb_last_error()); } $query = $_REQUEST['q']; // check if the query is at least there if (trim($query) == "") { err(400, "Missing query GET/POST parameter (?q=SELECT...)"); } if (isset($_REQUEST["callback"]) && !empty($_REQUEST["callback"])) { $hasJsonp = true; $jsonp = $_REQUEST["callback"]; if (!ereg("^[[:alnum:]_]+\$", $jsonp)) { err(400, "Invalid callback request parameter"); } }