Mysql
 sql >> Database >  >> RDS >> Mysql

PDO + MySQL restituisce sempre stringhe, ma per quanto riguarda MsSQL?

Se vuoi assicurarti di ottenere sempre le stringhe puoi usare bindColumn() e specificare il tipo di dati per ogni colonna

$sql = 'SELECT id, name FROM test';
$stmt = $dbh->query($sql);
/* Bind by column number */
$stmt->bindColumn(1, $id, PDO::PARAM_STR); //or PDO::PARAM_INT
$stmt->bindColumn(2, $name, PDO::PARAM_STR);
while ($row = $stmt->fetch(PDO::FETCH_BOUND)) {
  var_dump($id); var_dump($name);
}