|
|
|||
|
Many database application developers rely on the LAMP model, which in our world is the acronym for Linux-Apache-MonetDB-{PHP,Perl,Python}. We illustrate the infrastructure using PHP. The other APIs are described in more detail in the general documentation (See @ref{Programming Interfaces}). Webservice initializationMake sure you have installed both the MonetDB software, a working Apache server, and PHP5. In the MonetDB installation directory lib/php5 you will find the library php_monetdb.dll (or php_monetdb.so) for PHP5 coupling functionality. Copy this library to your PHP5 extension folder (directory) and add it as an extension to your php.ini file. The functionality of the module follows conventions in other database systems. A simple PHP exampleWe are now ready for running a simple MonetDB-PHP5 application. Copy the code below to your web-application directory and open the file in a browser. Make sure you have already started the MonetDB server.
<html>
<head>
<title>MonetDB Query</title>
</head>
<body>
<?php
if ( isset($_POST['query']) )
{
$db = @monetdb_connect('sql', 'localhost', 50000, 'monetdb', 'monetdb')
or die('Failed to connect to MonetDB<br>');
$sql = stripslashes($_POST['query']);
$res = monetdb_query($sql);
while ( $row = monetdb_fetch_assoc($res) )
{
print "<pre>\n";
print_r($row);
print "</pre>\n";
}
}
print "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">\n";
print "<label for=\"query\">SQL Query:</label>\n";
if ( isset($_POST['query']) )
$value = htmlentities($_POST['query']);
else
$value = '';
print "<input type=\"text\" name=\"query\" id=\"query\"
value=\"$value\">\n";
print "<input type=\"submit\" value=\"Execute\">\n";
print "</form>\n";
?>
</body>
</html>
|
||||
| © 1994-2011 CWI | Contact us Legal HG web Bugs TestWeb | |||