PDO Operation database times error: Database not selected __ Database

Source: Internet
Author: User
Tags dsn
I'm just learning to use PDO to manipulate the database, but, after connecting to the database, use Query () to execute the SELECT query statement, but always error: No database selected, code and error information as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");

$dsn = ' Mysql:dbname =pdo;host=localhost ';
$user = ' root ';
$pass = ' 086437 ';
$DBH = new PDO ($DSN, $user, $pass);

$DBH->setattribute (pdo::attr_errmode,pdo::errmode_exception);
$sql = ' SELECT * from PDO ';

$pdos = $dbh->query ($sql);
>
the error is: Fatal error:uncaught exception ' pdoexception ' with message ' sqlstate[3d000]: Invalid Catalog No Database Selected ' in D:\wamp\www\PDO\select.php on line -

pdoexception:sqlstate[3d000]: Invalid catalog name:1046 No Database selected in D:\wamp\www\PDO\select.php on line -
The error message is not connected to the database, but I clearly chose the $DSN = ' mysql:dbname =pdo;host=localhost ';Finally tried for a long time to find the original is Mysql:dbname =pdo; This sentence mysql:dbname should not be followed by a space, should be: mysql:dbname=pdo; I hope this experience will help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.