in reply to dbh connections: stumped!

Having written the script on a windows box, if you uploaded it to a unix or linux server, there is probably a problem on the shebang line, if the dos-specific CRLF line termination was not converted to unix LF. If the first line of your script (as it exists on the server) contains:
#!/usr/bin/perl\r\n
it won't run on the server. Get rid of the CR (use text-mode file transfer to the server, or dos2unix on the server after the script is uploaded.) Another work-around is to add a useful flag or two:
#!/usr/bin/perl -T -w
When you do that, you not only get the benefits of taint checking and warnings enabled (which you ought to do anyway for a cgi script!!), but also unix will correctly parse out the path to perl as /usr/bin/perl (rather than /usr/bin/perl\r).

Replies are listed 'Best First'.
Re^2: dbh connections: stumped!
by kevin (Initiate) on Mar 11, 2006 at 20:08 UTC
    OK, thanks very much for the help so far. I've implemented most of these suggestions, but the problem persists.

    1. I've stopped using CGI and "fatalsToBrowser".
    2. I've eliminate the "die" portion of the connect string.
    3. I contacted my web hosting provider, but got a terse "we don't debug code" type of reply.
    4. I re-uploaded the code after running dos2unix.

    Some more info: the connection line is

    my $dbh = DBI->connect('dbi:mysql:database=<i>dbname</i>;host=localhos +t','<i>uname</i>','<i>pword</i>');
    If I mangle the first argument, I get a "Can't connect to database" error, just like I should. If I mangle either of the other two arguments, I get the same results as in my original message, a blank Firefox document or a "This page cannot be displayed" IE error. This time, however, the following lines appear in my error log (the Apache error log):
    Use of uninitialized value in split at usr/local/lib/perl/5.8.4/Apache +.pm line 172.
    Stil stumped, but again, thanks for the help so far. Kevin
      localhost? On a remote host? My ISP has given me an IP address to use there. I would check with the ISP for the correct connection details.

      Best of luck.

      wfsp

      You haven't mentioned whether you have shell access on that server. If you did, you might be able to try out the mysql command on a command line, confirm that your connection parameters work that way at least, and generally poke around in your database account to make sure everything is kosher.

      I assume that your connection string does not actually include the html tags for "italic font" -- I think everyone here who is looking at your code is assuming that you put the  <i> ... </i> around "dbname", "uname" and "pword" just for the sake of posting, to clarify that you are (wisely) not showing us the real values that you actually use in those slots to make the connection.

      But just to be sure... if those "i" tags really are there in the script you're trying to run (and/or if that script isn't using the strings provided by the ISP for those slots), then that is surely the problem.