Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How bind ENUM type by number in PDO

Tags:

php

mysql

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);
........`
like image 310
Harry Avatar asked Apr 23 '26 00:04

Harry


1 Answers

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
like image 182
rink.attendant.6 Avatar answered Apr 25 '26 21:04

rink.attendant.6



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!