每次连接时如何让PDO适配器运行SET NAMES utf8?

时间:2017-03-15 14:50:31

标签: php mysql

public static void announceForAccessibility(Context context, String message) {
    AccessibilityManager manager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    if (manager.isEnabled()) {

        AccessibilityEvent e = AccessibilityEvent.obtain();
        e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        e.setClassName(context.getClass().getName());
        e.setPackageName(context.getPackageName());
        e.getText().add(message);

        manager.sendAccessibilityEvent(e);
    }
}

pdo set names utf8< - 我该怎么做

1 个答案:

答案 0 :(得分:-1)

试试这个:

$options = [
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
];

$this->connection = new PDO(
    'mysql:host=localhost:3307;dbname=project',
    'root',
    'usbw',
    $options
);

$this->connection->setAttribute(
    PDO::ATTR_ERRMODE,
    PDO::ERRMODE_EXCEPTION
);