On Mon, Feb 05, 2001 at 02:44:35PM +0800, [EMAIL PROTECTED] wrote:
> hi list,
>
> im trying to write a perl srcipt that will connect to a mysql
> database server, do some queries and print the output on the screen
> (or maybe append the output to a file), that would look something
> like this.
>
> +------+-------+----------+-------------+
> | tnum | user | cust | area |
> +------+-------+----------+-------------+
> | 22 | nivra | testing | isdn |
> | 23 | nivra | testing1 | ddu |
> | 24 | nivra | testing1 | ddu |
> +------+-------+----------+-------------+
>
> below is my perl script.
>
> #!/usr/bin/perl
>
> use DBI;
>
> $dbname= "dbname";
> $dbuser = "dbuser";
> $dbpass = "dbpass";
> $dbhost = "localhost";
> $dbport = "3306";
> $dsn = "DBI:mysql:database=$dbname;host=$dbhost;port=$dbport";
>
> $condition = " where date >= '2001/01/27' and petsa <= '2001/01/31' and
> user = 'user'";
>
> # Connect to the database
> $dbh = DBI->connect($dsn, $dbuser, $dbpass);
>
> # if needed and execute the SELECT
> $sth = $dbh->prepare("SELECT tnum, user, type, area, stat FROM
> tickets$where ");
> $output = $sth->execute;
>
> # clean up & disconnect from the DB
> $sth->finish;
> $dbh->disconnect;
> print $output;
>
> but it doesn't give me any output at all. i'd like to know if there
> is any special parameter to use with sth->execute to do this. did i
> miss anything here?
A couple of points:
(1) You should really `use strict' in your Perl code.
(2) The return value of $sth->execute is not what you expect. Check
the DBI docs to learn what it really is.
Jeremy
--
Jeremy D. Zawodny, <[EMAIL PROTECTED]>
Technical Yahoo - Yahoo Finance
Desk: (408) 328-7878 Fax: (408) 530-5454
Cell: (408) 439-9951
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php