0

i want to insert a query but not work :

my $query1 = $db1->prepare("SELECT host, name, severity  FROM XX");  
my $query2 = $db2->prepare('UPDATE worldmap_table' . ' SET severity = ?, name = ? WHERE HOST = ?');

$query1->execute;

while (my @row = $query1->fetchrow_array) {
    $query2->execute($row[2]);
    print "$row[2]\n";
}

preparation query 3

my $query3 = $db1->prepare("SELECT host, name, severity
  FROM XX);

preparation query 4

my $query4 = $db2->prepare('UPDATE worldmap_table' . ' SET severity = 6, name = ? WHERE HOST = ?');

$query3->execute;

this part not work

while (my @row2 = $query3->fetchrow_array) {
    $query4->execute($row2[2], $row2[1], $row2[0]);
    print "$row2[2], $row2[1], $row2[0] \n";
}

i have this error:

DBD::mysql::st execute failed: called with 3 bind variables when 2 are needed at worldmap2.pl line 103.
DBD::mysql::st execute failed: called with 3 bind variables when 2 are needed at worldmap2.pl line 103.
1
  • You seem to have left out important bits of your code like where you call execute on the prepared statement (And what you did include has errors and appears to be missing bits)... but the error message should be self-explanatory. Commented Mar 17, 2020 at 9:46

1 Answer 1

1

There are two placeholders in query 4:

my $query4 = $db2->prepare(
    'UPDATE worldmap_table' . ' SET severity = 6, name = ? WHERE HOST = ?'
    #                                                    ~              ~
);

But you're calling it with only one argument:

$query4->execute($row2[2]);
#                ~~~~~~~~

The error message mentions different numbers, so I guess you simplified the code.

Sign up to request clarification or add additional context in comments.

1 Comment

i changed the query 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.