|
|
|
|
| |
There is one unfortunate difference between the way the standard MySQL clients and the Getopt module handle command-line options. With Getopt, you cannot specify a password option (--password or -p) without an argument unless it is either the last argument on the command line or is immediately followed by another option. Suppose you have a script that expects a table name argument to follow the options. If invoked as follows, Getopt will interpret mytbl as the password value rather than prompting for a password:
% ./myscript.pl -u paul -p mytbl
To get the script to prompt for a password, put the -p option before the -u option:
% ./myscript.pl -p -u paul mytbl
Debugging
When you want to debug a malfunctioning DBI script, two techniques are commonly used, either alone or in tandem. First, you can sprinkle print statements throughout your script. This allows you to tailor your debugging output the way you want it, but you must add the statements manually. Second, you can use DBI's built-in tracing capabilities. This is more general and more systematic, and it occurs automatically after you turn it on. DBI tracing also shows you information about the operation of the driver that you cannot get otherwise.
Debugging Using Print Statements
A common question on the MySQL mailing list runs like this: "I have a query that works fine when I execute it using the mysql program, but it doesn't work from my DBI script. How come?" It's not unusual to find that the DBI script really is issuing a different query than the questioner thinks. If you print a query before executing it, you may be surprised to see what you're actually sending to the server. Suppose a query as you type it into mysql looks like the following:
mysql> INSERT INTO member (last_name,first_name,expiration)
-> VALUES('Brown','Marcia','2005-6-3');
Then you try the same thing in a DBI script (leaving out the terminating semicolon, of course):
$last = "Brown";
$first = "Marcia";
$expiration = "2005-6-3";
$query = qq{
INSERT INTO member (last_name,first_name,expiration)
VALUES($last,$first,$expiration)
};
$rows = $dbh->do ($query);
This doesn't work, even though it's the same query. Or is it? Try printing it:
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|