And the error is:SET @num := 0; SET @id := -1; SELECT e.*, y.ChallengerID, CASE WHEN ep.isChampion IS TRUE THEN TRUE +ELSE FALSE END AS isCurrentChampion FROM ( . . .
The query executes without a problem in MySQL. I do not know why put placing the execution of the SET statement directly into the Perl code using \@ seems to result in something that works. In this case, I removed the SET statement from the code.sql file but left the remainder of the SQL code in place...DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near 'SET @id := -1; SELECT e.*, y.ChallengerID, CASE WHEN ep.isChampion IS TRUE THE' at li +ne 2
#!/usr/bin/env perl use strict; use warnings; use DBI; use Data::Dumper; # MYSQL CONFIG VARIABLES my $host = "XYZ"; my $db = "XYZ"; my $dbuser = "XYZ"; my $dbpw = "XYZ"; # CONNECT TO MYSQL my $dbh = DBI->connect("DBI:mysql:$db", $dbuser, $dbpw) || die "Could +not connect to database: $DBI::errstr"; my $myquery; $myquery = "SET \@num := 0, \@id := -1;"; my $sth = $dbh->prepare($myquery); $sth->execute(); # Retrieve all open tests my $file = "../sql/code.sql"; { local $/ = undef; open FILE, $file or die "Couldn't open file: $!"; $myquery = <FILE>; close FILE; } print "\nSQL scheduling query constructed... executing..."; + $sth = $dbh->prepare($myquery); $sth->execute();
In reply to DBD and a MySQL query with a SET @num line by edieguez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |