> > At 04:01 PM 3/1/2003 +0000, Anadi Taylor wrote: > >Hi all, > > > >I have written a script that reads in information from a database: > >name, > >email, password and username. > > <snip nice description of problem> > > >Also: the only reason I am having to pull all this data from > the mySql > >database is because for some very strange reason mySql doent > like the '@' > >and the '.' characters in a sql statement: I actually > started with a SQL > >query like: > > > >SELECT name, email, password, username FROM members WHERE > >email='[EMAIL PROTECTED]'; > > > >BUT - it really doesnt like this, any ideas why ???
Yes, mysql uses @ and . Are special symbols like $ is to perl. Also when you use dbi you don't put the ';' on the end of the query like you would if it was via the coommand line. I'd recommend removing the ; from the query in your script and one thing I always do if a query is giving me probs is $query = 'SELECT monkey from joemama'; print $query; Then take the generated $query ( which has the actual query vs. the query you *think* it is making. And run that via the mysql command line. Then if the query won't run you've found the erro is in the query an dif it works then the error is in you script's code. One other tool is DBI trace() routine. Perldoc -m DBI (look for trace) Mysql.com search for perl DBI trace Search.cpan.org DMuey > > OK, I had my second cup of coffee now. Maybe you are just > going about it > the wrong way. Try this, or a variation of it, for MySQL > server or any SQL > server for that matter: > > #!/usr/bin/perl -w > > use strict; > use DBI; > my $driver_handle = DBI->install_driver("mysql"); > # No sense doing anything if we don't have mysql drivers > installed if ($driver_handle) { > my $dbh = $driver_handle->connect("database=test","root",""); > # change test, root and "" to your DB name, user and password > > # use single quote here not " or you'll have grief > my $srcEmail = '[EMAIL PROTECTED]'; > > # always use a quoter to build your queries... > # I like to use qq[] with single quotes around variables for > dynamic SQL > my $SQL = qq[SELECT name, email, password, username > FROM mytest > WHERE email='$srcEmail' > ]; > > my $sth = $dbh->prepare($SQL); > > # print "$SQL\n"; # Use this line for debugging query. > > $sth->execute; > > # a nice way to prename variables instead of using an array > while ( my ($dbname, $dbemail, $dbpwd, $dbusrname) > = $sth->fetchrow_array ) > { > print "$dbname, $dbemail, $dbpwd, $dbusrname\n"; > # or whatever you want to do with these vars. > } > > $dbh->disconnect( ); > } > else { print "Need Drivers for MySQL!\n"; } > > --------- > Hope this helps you get to where you want to be. > > Scott. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]