老是出現(xiàn)boolean false
<?php
try {
? ? $pdo = new PDO('mysql:host = localhost;dbname = test', 'root', '');
? ? //exec():執(zhí)行一條sql語(yǔ)句返回受影響的記錄的條數(shù),去過(guò)沒(méi)有受影響的記錄,他返回0
? ? //exec對(duì)select不起作用
? ? $sql = <<<EOF
? ? create table if not exists user(
? ? id int unsigned auto_increment key,
? ? username varchar(20) not null unique,
? ? password char(32) not null,
? ? email varchar(30) not null
? ? );
EOF;
? ? $res = $pdo ->exec($sql);
? ? var_dump($res);
} catch (PDOException $e) {
? ? $e ->getMessage();
}
2019-05-29
哥們,解決了嗎,我的沒(méi)有空格,也出這個(gè)問(wèn)題,顯示連接成功,返回的對(duì)象是空的
2017-04-05
$pdo = new PDO('mysql:host = localhost;dbname = test', 'root', '');
把這句里面的mysql:host = localhost;dbname = test的空格全部去掉就OK了