完成系统安装后,我们现在终于可以运行一个模型应用程序了。根据安装的 msql 版本和使用的 perl 数据库接口,我们必须在一些地方修改示例程序。
然而,首先必须修改位于 /home/httpd/html/
中的 index.html
文件,以允许调用示例数据库应用程序。我们可以将我们的数据库(在这里我们称之为 database.cgi
或 inventur.cgi
,尽管它的存档名称是 perl.lst.ck
)放在 /home/httpd/html/test/
中。
我们向 index.html
添加一行(当然,取决于您的安装选择),类似于以下内容
<LI>Test the <A HREF="test/database.cgi">Database, DBI:DBD-mSQL style!</A> <LI>Test the <A HREF="test/inventur.cgi">Database, MsqlPerl style!</A>
我们的示例脚本必须被告知使用 MsqlPerl 接口。修改发生在几个地方。首先,在文件开头附近,我们更改 use
子句
# # use DBI; # Generisches Datenbank-Interface use Msql;
然后,在第 27 行附近,MsqlPerl 语法不需要提及特定的驱动程序
# $dbh = DBI->connect($host, $database, '', $driver) || $dbh = Msql->connect($host, $database) ||
然后,从第 33 行开始,在整个脚本中,我们必须将所有 do
实例更改为 query
# $dbh->do("SELECT * FROM hw") || db_init($dbh); $dbh->query("SELECT * FROM hw") || db_init($dbh);
最后,在 MsqlPerl 语法中,可以注释掉第 207 行
# $sth->execute || msg("SQL Error:", $sth->errstr);
此外,可能有必要将所有 errstr
调用(例如前面代码片段中的那个)替换为 errmsg
。 这也取决于版本。
经过这些修改后,脚本应该可以顺利运行。
SQL 语法在 mslq-2 的开发过程中被重新定义。原始脚本将无法执行第 45 -- 58 行中的表初始化语句。 msql-2 不再支持 primary key
修饰符,应该简单地跳过它
$dbh->do(<<EOT) || die $dbh->errstr; # Neue Personen-Tabelle create table person ( # We do not need the 'primary key' modifier anymore in msql-2! # pn int primary key, # Personalnummer pn int, # Personalnummer name char(80), # Nachname, Vorname raum int # Raumnummer ) EOT $dbh->do(<<EOT) || die $dbh->errstr; # Neue Hardware-Tabelle create table hw ( # We do not need the 'primary key' modifier anymore in msql-2! # asset int primary key, # Inventurnummer asset int, # Inventurnummer name char(80), # Bezeichnung person int # Besitzer ) EOT
不幸的是,这个特定的脚本随后将接受具有相同人员编号的新条目;msql-1 修饰符 primary key
旨在防止这种行为。 msql-2 文档展示了如何使用 CREATE INDEX
子句来创建唯一条目。