update core

This commit is contained in:
Paul Spenke
2023-06-18 20:45:00 +08:00
parent de0f453003
commit 8db48bb9ab
14 changed files with 192 additions and 288 deletions
+35
View File
@@ -2,6 +2,7 @@
namespace Plugi\Core;
use Exception;
use PDO;
/**
@@ -106,4 +107,38 @@ class DB
$stmt = $this->pdo->prepare($query);
return $stmt->execute($parameters);
}
function tableExists($table) {
// Try a select statement against the table
// Run it in try-catch in case PDO is in ERRMODE_EXCEPTION.
try {
$result = $this->pdo->query("SELECT 1 FROM {$table} LIMIT 1");
} catch (Exception $e) {
// We got an exception (table not found)
return FALSE;
}
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
return $result !== FALSE;
}
/**
* Perform a custom query with user input data passed as $parameters.
*
* @param string $table
* @param string $sql
* @return bool
*/
public function prepare(string $table, string $sql)
{
// check if table with the name $table exists. if not, execute $query.'
try {
$result = $this->pdo->query("SELECT 1 FROM {$table} LIMIT 1");
return TRUE;
} catch (Exception $e) {
$stmt = $this->pdo->prepare($sql);
return $stmt->execute();
}
}
}