Postingan lainnya
Error Menampilkan Data dari database dengan koneksi pdo
Selamat Siang gan ane lagi belajar php.. koneksi database sudah berhasil tapi ane dapet error pas mau nampilin data. tolong dibantu :)
Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in C:\xampp\htdocs\portalberita\index.php:56 Stack trace: #0 C:\xampp\htdocs\portalberita\index.php(56): PDO->query('SELECT *FROM is...') #1 {main} thrown in C:\xampp\htdocs\portalberita\index.php on line 56
koneksi.php
<?php
//variabel
$server="localhost";
$user="root";
$password="";
$nmdatabase="newspaper";
//variabel koneksi
try {
$conn=new PDO ("mysql:host=$server;nmdatabase=$nmdatabase", $user, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo "Berhasil Konek Database!!!";
} catch (PDException $e) {
echo 'Error : '.$e->getMessage();
}
?>
index.php
<?php
include 'koneksi.php';
$result = $conn->query('SELECT * FROM isiberita');
//die(var_dump($result->fetch()));
while ($row = $result->fetch()) {
echo $row['judul'] . '<br>';
}
?>
0
3 Jawaban:
$conn=new PDO ("mysql:host=$server;dbname=$nmdatabase", $user, $password);
0