Example #1
0
<?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);
}
Example #2
0
<?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();
Example #3
0
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";
}
Example #4
0
<?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);
}
Example #5
0
<!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";
?>
	
Example #6
0
$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");
    }
}
// actual querying
$res = monetdb_query($db, monetdb_escape_string($query));
if (!$res) {
    err(400, "Invalid query: " . monetdb_last_error());
}
// construct result emtadata
$json = array();
$json["metadata"] = $res["header"];
$json["metadata"]["counts"] = $res["query"];
$json["metadata"]["query"] = $query;
$json["results"] = array();
// ok, construct result json. Simply fetch each row as an assoc array and append
while ($row = monetdb_fetch_assoc($res)) {
    $json["results"][] = $row;
}
// encode result correctly, depending on whether we want jsonp or not
if ($hasJsonp) {
    header("Content-Type: application/javascript");
    print $jsonp . "(" . json_encode($json) . ");";