Database html
From DreamsteepWiki
PHP IN HTML
<html> <head></head> <body> <h1> <?php echo "THE HORROR!"; ?> </h1> </body> </html>
FETCHING GEOMETRY BY INDEX IN A PHP
<html>
<head>
</head>
<body>
<?php
$dbconn = pg_connect("host=127.0.0.1 dbname=bentonpg user=postgres password=password")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$GEOMCOL = 'geom'; //the geometery (column ?)
$GEOMTAB = 'gtest'; //the name of the postgis table
$ID_TABLE = 'id'; //the name of the index field
$INDEX_TO_GET = 1;
//$query = 'SELECT * FROM '. $GEOMCOL;
//$query = 'SELECT ST_asText(' . $GEOMCOL . '.the_geom) AS the_WKT_Output FROM codata.taxprj WHERE ' . $GEOMCOL . '.taxlots_fe = 1';
$query = 'SELECT ST_asText(' . $GEOMCOL . ') FROM '.$GEOMTAB.' WHERE '.$ID_TABLE.' = '.$INDEX_TO_GET.' ;';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$arr = pg_fetch_array($result, 0, PGSQL_NUM);
print"\n";
echo $arr[0] ;//."in php______";
print"\n";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
//<!-- pt language="javascript" type="text/javascript">
// var WKTstring = "poly in JS is \"<Xphp echo($arr[0]);?>\"";
// document.write(WKTstring);
//</scr -->
?>
</body>
</html>
PGQUERY
<?php
$conn = pg_connect("host=127.0.0.1 dbname=bentonpg user=postgres password=password") ;
if (!$conn) {
echo "An error occured.\n";
exit;
}
$result = pg_query($conn, "SELECT id, character FROM characters");
if (!$result) {
echo "An error occured.\n";
exit;
}
while ($row = pg_fetch_row($result)) {
echo "Author: $row[0] E-mail: $row[1]";
echo "<br />\n";
}
?>
INTERACTING WITH DATABASES VIA PGCONNECT
<?php
// Connecting, selecting database
$dbconn = pg_connect("host=127.0.0.1 dbname=bentonpg user=postgres password=password")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$query = 'SELECT * FROM cartoons';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
print $col_value;
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>
UNTESTED
$connection = mysql_connect($server,$uzivatel,$heslo) or die ("Spojení k databázi se nezdařilo.");
$database = mysql_select_db("rybydb");
$vypis_bodu = mysql_query("SELECT * FROM bod WHERE id_ul LIKE '$bodka'");
$x_s = MySQL_Result($vypis_bodu, 0,"x_sour");
$y_s = MySQL_Result($vypis_bodu, 0,"y_sour");
$pointobj = ms_newPointObj();
$pointobj->setXY($x_s,$y_s);
$lineobj = ms_newLineObj();
$lineobj->add($pointobj);
$pointobj->free();
$shapeobj = ms_newShapeObj(MS_SHAPE_POINT);
$shapeobj->add($lineobj);
$lineobj->free();
$layerobj = ms_newLayerObj($map);
$layerobj->set('type',MS_LAYER_POINT);
$layerobj->set('status',MS_ON);
$layerobj->addFeature($shapeobj);
$classobj = ms_newClassObj($layerobj);
$classobj->set('symbol',1);
$classobj->set('size',20);
$newColor = $map->addColor(255,0,0);
$classobj->set("color", $newColor);
Thanks for your answer but i was looking for this.
function createPoint( $x1, $y2, $programId, $radius)
{
GLOBAL $shpFile, $dbfFile;
// Create shape
$oShp = ms_newShapeObj(MS_SHAPE_POLYGON);
$oLine = ms_newLineObj();
$pointObj = ms_newPointObj();
for ($i = 0; $i <= 360; $i = $i + 10)
{
$x = $x1 + (cos($i * (22 / 7) / 180) * $radius);
$y = $y2 - (sin($i * (22 / 7) / 180) * $radius);
$pointObj->setXY($x, $y);
$oLine->add($pointObj);
}
$oShp->add($oLine);
$shpFile->addShape($oShp);
// Write attribute record
dbase_add_record($dbfFile, array($programId));
}
$shpFname = "/var/www/html/atmsv03/testpol";
$shpFile = ms_newShapeFileObj($shpFname, MS_SHP_POLYGON);
$dbfFile = dbase_create( $shpFname.".dbf", array(array("ID", "N", 5,
0)));
// geopoint1 and 2 and 100 is the radius
createPoint($punt[0], $punt[1], 1, 100);
$shpFile->free();
dbase_close($dbfFile);
// Set the buffer distance
$pt_layer = $map->getLayerByName("polygon");
$pt_layer->set("status", MS_ON);
$pt_layer->set("transparency", 50);
$pt_class = $pt_layer->getclass(0);
MAP FILE
LAYER
NAME "polygon"
TYPE POLYGON
STATUS OFF
DATA testpol
CLASS
NAME 'Europa'
COLOR 255 0 0
OUTLINECOLOR 0 0 0
END
END # layer
here is a sample piece of code in PHP with mapscript module wich extract
X,Y from a postgresql table and create a shapefile on the fly. comments
are in french, sorry.
// On ouvre un shapefile unique de points
$shapetempname="tmp/tmp".time();
$shapefile_temp=ms_newShapefileObj("../data/$shapetempname",
MS_SHP_POINT);
//création d'un fichier dbase
// son nom
$dbname="../data/$shapetempname".".dbf";
// sa structure
$def= array(array("nom", "C", 20),array("uai_cdn", "N", 15, 0));
// création proprement dite de sa structure
$dbid=dbase_create("$dbname",
$def);dbase_pack($dbid);dbase_close($dbid);
// réouverture du fichier en rw
$dbidrw=dbase_open("$dbname", 2);
//connection à la B2D et extraction des X,Y
$conn = pg_connect("dbname=database host=localhost user=username
password='pass' port=5432 ");
$Query="select id,nom,e as x ,n as y from communes_pers LIMIT 150";
$Res = pg_exec ($conn, $Query);
$iNbr = pg_numrows($Res);
for ($i = 0; $i < $iNbr; $i++) {
$Lign = pg_fetch_array($Res, $i);
$pointobj = ms_newPointObj();
$pointobj->setXY($Lign["x"],$Lign["y"],1);
$shapefile_temp->addPoint($pointobj);
$pointobj->free();
$valuedbf=array($Lign["nom"],$Lign["id"]);
$test=dbase_add_record($dbidrw, $valuedbf);
}
dbase_pack($dbidrw);
dbase_close($dbidrw);
// On écrit le shapefile
$shapefile_temp->free();

