1 config.php PDO::ERRMODE_EXCEPTION, 12 13 PDO::ATTR_DEFAULT_FETCH_MODE => PDO:: FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, 14 ]; 15 16 try { 17 18 19 $pdo = new PDO($dsn, $user, $pass, $options); } catch (\PDOException $e) { throw new \PDOException($e->getMessage(), (int)$e->getCode()); 20 } 21 22

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi good day i'm getting this error when trying to access localhost for my database. is there any way this can be fixed. if so can you assist in a step by step format? it would help a lot thanks. if you require any more information please let me know. Also please see the code attached 


Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1049] Unknown database 'car_sales_db' in C:\xampp\htdocs\Tutorial\config.php:19 Stack trace: #0 C:\xampp\htdocs\Tutorial\index.php(2): require() #1 {main} thrown in C:\xampp\htdocs\Tutorial\config.php on line 19 


1
config.php
<?php
2 $host
= 'localhost';
3
$db
=
'car_sales_db';
4
$user
=
5
$pass
6
$charset
7
8
$dsn =
'terre'; // Replace with your MySQL username
// Replace with your MySQL password
'utf8mb4';
"mysql:host=$host; dbname=$db; charset=$charset";
9
10
$options [
11
PDO::ATTR_ERRMODE
=> PDO::ERRMODE_EXCEPTION,
12
13
PDO::ATTR_DEFAULT_FETCH_MODE => PDO:: FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES
=> false,
14
];
15
16
try {
17
18
19
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
20
}
21
22
Transcribed Image Text:1 config.php <?php 2 $host = 'localhost'; 3 $db = 'car_sales_db'; 4 $user = 5 $pass 6 $charset 7 8 $dsn = 'terre'; // Replace with your MySQL username // Replace with your MySQL password 'utf8mb4'; "mysql:host=$host; dbname=$db; charset=$charset"; 9 10 $options [ 11 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, 12 13 PDO::ATTR_DEFAULT_FETCH_MODE => PDO:: FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, 14 ]; 15 16 try { 17 18 19 $pdo = new PDO($dsn, $user, $pass, $options); } catch (\PDOException $e) { throw new \PDOException($e->getMessage(), (int)$e->getCode()); 20 } 21 22
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education