Handling Quotes : MySql « Database « Perl






Handling Quotes

   

use DBI;
$dbh=DBI->connect(qq(DBI:mysql:database=sample_db;user=root;password=)) or die "Can't connect";
$namestring=qq(O'C);
$namestring=$dbi->quote($string);
print $namestring;
$sth=$dbi->prepare("SELECT * FROM Employee WHERE name=$namestring") or die "Can't prepare sql statement" . DBI->errstr;
$sth->execute();

while(my @val = $sth->fetchrow_array()){
       print "id=$val[0]\n";
       print "name=$val[1]\n";
       print "name=$val[2]\n";
       print "name=$val[3]\n";
       print "start_date=$val[4]\n\n";
}

$sth->finish();
$dbh->disconnect();

   
    
    
  








Related examples in the same category

1.Deleting Entries
2.Dumping a Query's Results
3.Error Diagnostic Variables
4.Inserting into a Database
5.Load text file to database
6.MySQL Data Types
7.Preparing a Statement Handle and Fetching Results
8.Pushing Query Results to an Array to Find Wildcard Hosts
9.Query parameter binding
10.Retrieving Query Results Listing MySQL Users and Hosts
11.Retrieving an Index ID