Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm new to pdo just tried the following and getting fatal error.

$pdo = new pdo('mysql:localhost;widget_corp;charset=utf-8', 'root', '');
$query = $pdo->query("SELECT * FROM 'users'");
$result_array = $query->fetchAll(PDO::FETCH_ASSOC);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

Change:

mysql:localhost;widet_corp

to

mysql:host=localhost;dbname=widget_corp

Also in your posted code:

$query = $pdo->query("SELECT * FROM 'users'");

you have the table name inside single quotes. In Mysql you should use a backtick instead for tables and columns.

    $query = $pdo->query("SELECT * FROM `users`");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...