Not able to perform a PDO Prepare Statement

330 Views Asked by At

'm trying to execute the following code:

try 
{
    $conn = new PDO('odbc:Clasges5');           
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO codpais (clapai,codpas,nompas) VALUES (:clapai,:codpas,:nompas)";
    $q = $conn->prepare($sql);
    $clapai = 31;
    $codpas = 'test codpas';
    $nompas = 'test nompas';
    $q->bindParam(':clapai', $clapai, PDO::PARAM_INT);
    $q->bindParam(':codpas', $codpas, PDO::PARAM_STR);
    $q->bindParam(':nompas', $nompas, PDO::PARAM_STR);
    $q->execute();        
}
catch(Exception $e)
{
echo $e->getMessage();
}

The database (VisualFox DBase via ODBC) looks like this: - table codpais - clapai primary key - codpas string - nompas string

I'm getting the error Invalid character value for cast specification: 302

The problem is the "clapai". If i perform an update with codpas or nompas everything works OK, if i try tu update the clapai value it throws the same error.

Any tips to fix that? BTW. It's better to use the named placeholders or the question marks? any advantage?

0

There are 0 best solutions below