[GENERAL] Postgres' DBI(Pg) problems.

Поиск
Список
Период
Сортировка
От R\imi Lehn
Тема [GENERAL] Postgres' DBI(Pg) problems.
Дата
Msg-id 13986.62142.701726.19922@kir.performanse.com
обсуждение исходный текст
Ответ на Postgres' DBI(Pg) problems.  (Kevin Lo <jwlo@ms11.hinet.net>)
Список pgsql-general
    Your script worked for me (I skipped everything related to
forms-lib), but :

- /* xxxx */ C-style comments are not allowed by perl (line #2)
- you should $sth->finish() and $dbh->disconnect() at the end of your
  script to avoid warnings ("Database handle destroyed without
  explicit disconnect.")

    I assumed that your table course has two fields, both are
type text. Check that your fields are not numbers (inserted values
are quoted (line #13)).

    You can replace $sth->prepare() and $sth->execute() by a
$sth->do( "your query" ); as your query has no output row.

    Check your web server's logs. At least for apache, stderr
of cgi scripts is dumped in an error log. Try running your script
offline. A common mistake is not having access to your database
with the uid endorsed by your web server (apache usually runs
cgi scripts as nobody which may not have INSERT permissions on
the table).

Hope it will help.
Rémi.

Kevin Lo writes:
 > Hi,
 >
 > I'm trying to use Postgres DBI, which is Pg, to write a simple cgi script.
 > But I encounter a problem, hope anyone can tell me how to do, thanks.
 >
 > For example:
 > I have two input forms in ex.html, which names are 'id' and 'student'.
 > I want to insert them into 'course' table in student database by using Pg.
 > The script I wrote as following:
 >
 > #!/usr/local/bin/perl
 > require 'forms-lib.pl';/* this script gets form values in HTML that I input */
 > use DBI;
 > print "Content-type: text/html\n\n";
 > print "<HTML>\n";
 > print "<HEAD>\n";
 > print "<TITLE>Data inserted</TITLE>\n";
 > print "</HEAD>\n";
 > %input = &GetFormInput();
 > $v1 = $input{'id'};
 > $v2 = $input{'student'};
 > $dbh = DBI->connect("dbi:Pg:dbname=student") or die $DBI::errstr;
 > $sth = $dbh->prepare("insert into course values('$v1', '$v2')")
 >      or die $DBI::errstr;
 > $sth->execute or  die $DBI::errstr;
 > print "<BODY>\n";
 > print "<H1>Data inserted!</H1>\n";
 > print "</BODY>\n";
 > print "</HTML>\n";
 >
 > After executing this script, I just see brower's title "Data inserted",
 > I can't see "Data inserted!" in HTML and can't insert values into 'course'
 > table. I don't know how to do, would anyone tell me, thanks in advance.
 >
 > Best regards,
 > Kevin.
 >
 >

В списке pgsql-general по дате отправления:

Предыдущее
От: Dave Van Abel
Дата:
Сообщение: Postgres Archive for Sample Code
Следующее
От: Gilles Darold
Дата:
Сообщение: Re: [GENERAL] How to display stored image on web page?