开发者

How can I bind the values of the parameter in the SQL statement using Perl?

开发者 https://www.devze.com 2023-01-18 14:02 出处:网络
HI am using SQLite DB and whenev开发者_StackOverflow中文版er I try to bind the values of parameter into the statement I am getting an error.

HI am using SQLite DB and whenev开发者_StackOverflow中文版er 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?


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.


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


my $sql = "INSERT INTO table 
                       (name, age)
           VALUES 
                       ('$name', ?);

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

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

精彩评论

暂无评论...
验证码 换一张
取 消