Harry
Harry

Reputation: 344

How bind ENUM type by number in PDO

Is it possible to bind MySQL ENUM type by its number in PDO statement, like:

$stm = $pdo->prepare( "insert into `my_table` (`id`, `enum_type`) values (?, ?)");
$stm->bindParam( 1, $id, PDO::PARAM_INT);
$stm->bindParam( 2, $number, PDO::PARAM_INT);
........`

Upvotes: 3

Views: 5290

Answers (1)

rink.attendant.6
rink.attendant.6

Reputation: 46228

PDO::PARAM_STR should be safe for enumerated values as I believe they are stored as string/string-based data types in the database itself.

In fact, PDO defaults to PDO::PARAM_STR for an unspecified parameter type as is visible in its signature:

 public PDOStatement::bindParam(
    string|int $param,
    mixed &$var,
    int $type = PDO::PARAM_STR,
    int $maxLength = 0,
    mixed $driverOptions = null
): bool

Upvotes: 1

Related Questions