Public
Authored by Vlastimil Pospíchal

MySQL Enum

<?php
$dbattr = array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
);
$db = new PDO('mysql:host=localhost;dbname=test', null, null, $dbattr);
$db->query("DROP TABLE IF EXISTS enumtest");
$db->query("CREATE TABLE enumtest(
    vycet ENUM('příšerně', 'žluťoučký kůň', 'úpěl', 'ďábelské,:-> ódy'))
    charset=UTF8"
);
$insert = $db->prepare("INSERT INTO enumtest VALUES (?)");
$insert->execute(array('příšerně'));
$insert->execute(array('žluťoučký kůň'));
$insert->execute(array('ďábelské,:-> ódy'));
foreach($db->query("explain enumtest", PDO::FETCH_ASSOC) as $row) {
    print_r($row);
}
foreach($db->query("select * from enumtest", PDO::FETCH_ASSOC) as $row) {
    print_r($row);
}
$db->query("ALTER TABLE enumtest MODIFY
    vycet ENUM('příšerně', 'unavený', 'žluťoučký kůň', 'úpěl', 'ďábelské,:-> ódy')"
);
foreach($db->query("explain enumtest", PDO::FETCH_ASSOC) as $row) {
    print_r($row);
}
foreach($db->query("select * from enumtest", PDO::FETCH_ASSOC) as $row) {
    print_r($row);
}
13 Bytes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment