Mysql PDO connected with right user,pass & DB name, but in working it shows SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘database.table’

This is my PDO config.php file:

<?php

Class Database{
    // private $server = "mysql:host=localhost;dbname=bdonesho_ther";private $username="**********";private $password = "*************";

    private $options  = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,);
    protected $conn;
    
    public function open(){
        try{
            $this->conn = new PDO($this->server, $this->username, $this->password, $this->options);
            return $this->conn;
        }
        catch (PDOException $e){
            echo "There is some problem in connection: " . $e->getMessage();
        }
 
    }
 
    public function close(){
        $this->conn = null;
    }
 
}

$pdo = new Database();
 
?>

and my SQL syntax is:

try{
$stmt = $conn->prepare("SELECT * FROM category ORDER BY RAND() LIMIT 25");
$stmt->execute();
foreach($stmt as $row){}
}catch (PDOException $e){echo $e->getMessage();}
?>

It shows:

SQLSTATE[42S02]: Base table or view not found: 1146 Table
‘bdonesho_ther.products’ doesn’t exist

My database collation is utf8_unicode_ci
and my tables are in utf8_unicode_ci, utf8_general_ci, latin1_swedish_ci

Leave a Comment