rule-www
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Rule-www] RULE call for:db, downloads, translations


From: Martin Stricker
Subject: Re: [Rule-www] RULE call for:db, downloads, translations
Date: Mon, 14 Oct 2002 23:31:53 +0200

Marco Fioretti wrote:
> 
> On Sun, Oct 13, 2002 21:04:07 at 09:04:07PM +0200, Martin Stricker

> > Suggested database design: Two tables, "test_pc" and "test_report".
> > The first gets it's primary key out of a sequence (AUTO_INCREMENT),
> 
> If you can email (even offlist) pseudo, rough Perl code doing this,
> I'll study how to rewrite it

You just need to fire some SQL statements at the database: CREATE
SEQUENCE and CREATE TABLE (sequence first so you can use it in the table
statement). Hmmmmm, check MySQL doc first, I'm not sure if MySQL
supports sequences, I'm currently doing IBM DB2 and (ick!) Oracle).

Perl uses a database-independent general API, which uses always the same
function names., while PHP AFAIK uses different function names for each
database (making migration a real pain). That said, I assume all here
are interested in a code snipplet:

====================================================================

#!/usr/bin/perl -w

use DBI;
use strict;

my $data_source="dbi:mysql:servername:databasename:portnumber";
my $user="user";
my $password="secret password";

# connect to database, use database handle $dbh
my $dbh=DBI->connect($data_source, $user, $password)
    or die "Error connecting to database: $DBI::errstr\n";

# prepare the SQL statement to be executed
my $sth=$dbh->prepare("SELECT * FROM table")
    or die "Error preparing the SQL statement: $DBI::errstr\n";

# now actually ask the database:
$sth->execute
    or die "Error executing: $DBI::errstr\n";

# Only for SELECT statements: Fetch the result row(s)!
my @row;
while(@row=$sth->fetchrow_array())
{
    print "data row: ", join("@@@", @row);
}
warn "Premature end of data because of error: $DBI::errstr\n"
    if $DBI::err;
$sth->

# disconnect: destroy $dbh
$dbh->disconnect
    or warn "Error while disconnecting: $DBI::errstr\n";

exit 0;

====================================================================

That should give you the idea. Are you skilled with setting up a data
model (including normalizing) for a database? If not I'll help. Step one
of this: Identify what information should go into the database.
Comments?

> About the request for translation to put in what I called the "empty
> page": isn't it better to create a Perl-like site-wide hash with one
> entry per language:
> 
>         'it', 'Questa pagina non esiste ancora, vorresti tradurla?'
        'de', 'Diese Seite wurde noch nicht ins Deutsche übersetzt,
daher hier die englische Originalfassung. Wenn Sie diese Seite ins
Deutsche übersetzen möchten, informieren Sie sich bitte auf der Seite <A
href="translations.php">&quot;Wie übersetze ich für RULE?&quot;</A> und
nehmen Sie mit <A href="mailto:address@hidden";>John Doe</A> Kontakt
auf. Vielen Dank!'

> so that if en/index.php is called like "en/index.php?L=de"
> it inserts the 'de' entry in nice bold red font right at the top of
> the page?

Absolutely! I just jotted down my comments, I wasn't in "software
profiling" mode...
BEGIN
{
    use MartinStricker::SoftwareProfilingMode;
}

;-)))

Best regards,
Martin Stricker
-- 
Homepage: http://www.martin-stricker.de/
Linux Migration Project: http://www.linux-migration.org/
Red Hat Linux 7.3 for low memory: http://www.rule-project.org/
Registered Linux user #210635: http://counter.li.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]