ImagjneAlex
New member
0
0%
3
Months of Service
0%
Hello friends, I am developing a blog script. However, I am encountering the following errors while establishing a data connection: Unable to connect to the database. Notice: Undefined variable: db in C:\wamp\www\tech-blog\header.php on line 4 Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\wamp\www\tech-blog\header.php:4 Stack trace: #0 C:\wamp\www\tech-blog\tech-index.php(2): include() #1 {main} thrown in C:\wamp\www\tech-blog\header.php on line 4 The code is as follows: In the file baglan.php; try { $db = new PDO("mysql:host=localhost; dbname=blog; charset=utf8;","root",""); } catch (PDOException $error) { echo "Unable to connect to the database"; $error->getMessage(); } ?> Within the header: $ayarlar = $db->prepare("SELECT * FROM settings"); $ayarlar->execute(); $settings = $ayarlar->fetch(PDO::FETCH_ASSOC); ?> My PHP version is 7 EDIT: ISSUE RESOLVED.