How to solve this, help me

i got this error

PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in C:\xampp\htdocs\crudsamp\notelist.php:11 Stack trace: #0 C:\xampp\htdocs\crudsamp\notelist.php(11): PDOStatement->execute() #1 {main}

this is my code

<?php

header("Access-Control-Allow-Origin: *");

require("db_conn.php");

$sql = "SELECT * FROM `tblnotes` ";
try {
	$result = $conn->prepare($sql);
	
	$result->execute();
	
	if($result->rowCount()>0){
		$loadlist = array();
		
	while($row=$result->fetch(PDO::FETCH_ASSOC)){
	    $loadlist_arr[] = array(
		                      "id" => $row["id"],
                              "task" => $row["task"],
							 
		                    );
}
echo json_encode($loadlist_arr);
}

}catch(PDOException $e){
	
	die( "An error has been occured!" . $e);
}
?>

Your database connection isn’t being configured to select a database. The problem is likely in db_conn.php.

Let’s see what’s your code inside db_conn.php :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service