Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

88 Part I — Basics


Listing 5-24: Inserting Data with Perl

#!/usr/bin/perl

use DBI;

my $dbh = DBI-
>connect(“DBI:mysql:database=google_maps;host=mysql.mcslp.pri”,’maps’,’maps’);

if ($dbh)
{
print “Connected to database\n”;
}
else
{
print “Couldn’t connect\n”;
}

$dbh->do(“insert into restaurants values(0,-0.6391666,52.911111,’China Inn’);”);

$dbh->disconnect();

Text being inserted into a database must be quoted using single or double quotation marks.
Which you use depends on what kind of quotation marks you have used to build the rest of the
query. The DBD interface also provides the quote()method to the database handle, which will
appropriately quote a given string of text, even if it already contains quotation marks.

Listing 5-25: Inserting Data with PHP (Traditional)

<?php

mysql_connect(localhost,’maps’,’maps’);

@mysql_select_db(‘google_maps’);

mysql_query(“insert into restaurants values(0,-0.6391666,52.911111,’China
Inn’)”);

mysql_close();

?>
Free download pdf