I want to add data to a table with user accounts that contains a column of type SET
roles set('user','admin') NOT NULL
In PHP the value is stored in an indexed array of strings.
I am binding the parameter with
$st = $conn->prepare($q);
...
// $pv is the value which causes the problem.
$r = array('user', 'admin');
// Nothing of these worked
// 1. Attempt, pass as the original array hoping PDO will take care
$pv = $r;
// 2. Convert to string with separator in various variations.
$pv = '\''.implode(',', $r).'\'';
// 2b.
$pv = '(\''.implode(',', $r).'\')';
// 2c.
$pv = '(\''.implode('\',\'', $r).'\')';
// 2d.
$pv = '\''.implode('\',\'', $r).'\'';
$st->bindParam(':roles', $pv);
I also tried
$conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, FALSE);
Executing the query always returns
"01000",1265,"Data truncated for column 'roles' at row 1"