Thread: Perl dbi with mysql problem
Results 1 to 2 of 2
Related
-
mysql & php new line problem Forum: PHP Forum
Replies: 6 -
perl and mysql-compare 2 columns Forum: CGI Perl Forum
Replies: 7 -
PERL-MYSQL connection using ODBC Forum: CGI Perl Forum
Replies: 0 -
how to set up Perl with MYSQL Forum: CGI Perl Forum
Replies: 0 -
MySql problem --with -- mysqlimport and TIMESTAMP Forum: Databases
Replies: 3
-
02-14-2005, 03:35 PM #1
Perl dbi with mysql problem
Im having problems using scalars in a sql statement to extract info from a mysql database, heres the code if anyone could help..
#Windows-based Perl/DBI/example
use DBI;
print "Search which field? "; # print out the question
my $data1; # declare" the variable
$data1 = <STDIN>; # ask for the username
chomp($data1); # remove "new line"
print "for what data? "; # print out the question
my $data2; # declare" the variable
$data2 = <STDIN>; # ask for the username
chomp($data2); # remove "new line"
#open connection to database
$dbh = DBI->connect('dbi:mysql:exelstock');
#prepare and execute SQL statement
my $string;
$string = "SELECT * FROM stock WHERE", ( '$data1' ) = ( '$data2' ) ;
$sth = $dbh->prepare( $string );
$sth->execute();
die "Could not execute SQL statement ... maybe invalid?";
#output database results
while (@row=$sth->fetchrow_array)
{ print "@row\n" }
-
02-14-2005, 04:26 PM #2
Hi, welcome to the forums.
I'm well rusty on Perl, so lets go with the basics.
Whats the result of printing $string out after you assigned the variables? That can tell us if there is anything wrong with the query.If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum