1

HI am using SQLite DB and whenever I try to bind the values of parameter into the statement I am getting an error.

Here's the piece of code:

my $sth = $dbh->prepare("SELECT UserId,UserName,CardNo,GroupId,Role,VerifyType FROM
    UsersList limit ?,? "); 
$sth->bind_param(1, undef,SQL_VARCHAR);
$sth->bind_param(2, undef,SQL_VARCHAR);
$sth->execute($page,$results_per_page);

Here's the error:

ERROR: DBD::SQLite::st execute failed: datatype mismatch at line 68.

Can anybody Please help me out and let me know what datatype am I supposed to put in place of SQL_VARCHAR?

3 Answers 3

5

Looks like you are using bind_param() wrong. Take a look at this example:

use DBI qw(:sql_types);  # Don't forget this

my $sth = $dbh->prepare(q{
    SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?;
});
$sth->bind_param(1, 5, SQL_INTEGER);
$sth->execute();

i.e.: no arguments to execute() and the value goes in the bind_param() call.

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

Comments

1

Limits are integers and not text, so I'd guess SQL_INTEGER might be a thing to try first?

1 Comment

I TRIED using SQL_INTEGER Also but the same error exists,i even used use DBI qw(:sql_types); but nothing is working ;-(
0
my $sql = "INSERT INTO table 
                       (name, age)
           VALUES 
                       ('$name', ?);

$sth = $dbh->prepare($sql);

#if not $age insert NULL value 
$sth->execute($age ? $age : undef); 

Comments

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.