Saturday, September 21, 2019

php mysql validate if table exist using pdo

I have the following code to see if a table (based on the user selection) exist or not, but it's giving me the following error:




[21-Mar-2019 11:34:11 UTC] PHP Fatal error: Uncaught PDOException:
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'filecleaner.opened_2019-03-21' doesn't exist in
C:\inetpub\wwwroot\FileCleaner\consultas.php:126 Stack trace:

0 C:\inetpub\wwwroot\FileCleaner\consultas.php(126): PDOStatement->execute(Array)
1 {main} thrown in C:\inetpub\wwwroot\FileCleaner\consultas.php on line 126




                 $pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare("SELECT * FROM filecleaner.`Opened_". $DataDeConsulta ."`");
$stmt->execute([$DataDeConsulta]);
$count = $stmt->fetchColumn();
if ($count <= 0) {

$DataDeConsultaError = 'There is no information on that date!';
$valid = false;
}
if (isset($valid)) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM filecleaner.`Opened_". $DataDeConsulta ."`";
//session_start();
$_SESSION['DataDeConsulta'] = $DataDeConsulta;
$query_result=$pdo->query($sql);

foreach ($pdo->query($sql) as $row) {
echo '';
echo ''. htmlentities($row['Emails']) . '';
echo ' ';
echo '';
echo '';
}
Database::disconnect();
}

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...