diff --git a/src/Database.php b/src/Database.php index a3cc36a48..7e0cad7c1 100644 --- a/src/Database.php +++ b/src/Database.php @@ -15,6 +15,7 @@ public static function connect($driver, $location, $user, $pass) self::$pdo = new PDO($dsn, $user, $pass); self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (Exception $e) { @@ -53,7 +54,14 @@ public static function query(SqlQuery $sqlQuery) if (!self::connected()) throw new Exception('Database is not connected'); $statement = self::makeStatement($sqlQuery); - $statement->execute(); + try + { + $statement->execute(); + } + catch (Exception $e) + { + throw new Exception('Problem with ' . $sqlQuery->getSql() . ' (' . $e->getMessage() . ')'); + } self::$queries []= $sqlQuery; return $statement; } diff --git a/src/Models/Entities/PostEntity.php b/src/Models/Entities/PostEntity.php index 4cf3a09cf..96f3be42d 100644 --- a/src/Models/Entities/PostEntity.php +++ b/src/Models/Entities/PostEntity.php @@ -70,9 +70,8 @@ public function getRelations() ->select('post.*') ->from('post') ->innerJoin('crossref') - ->on()->open()->raw('post.id = crossref.post2_id')->and('crossref.post_id = :id')->close() - ->or()->open()->raw('post.id = crossref.post_id')->and('crossref.post2_id = :id')->close() - ->put(['id' => $this->id]); + ->on()->open()->raw('post.id = crossref.post2_id')->and('crossref.post_id = ?')->close()->put($this->id) + ->or()->open()->raw('post.id = crossref.post_id')->and('crossref.post2_id = ?')->close()->put($this->id); $rows = Database::fetchAll($query); $posts = PostModel::convertRows($rows); $this->setCache('relations', $posts); diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php index a34ba1056..c7b6ced77 100644 --- a/src/Models/UserModel.php +++ b/src/Models/UserModel.php @@ -104,9 +104,8 @@ public static function findByNameOrEmail($key, $throw = true) $query = new SqlQuery(); $query->select('*') ->from('user') - ->where('LOWER(name) = LOWER(:user)') - ->or('LOWER(email_confirmed) = LOWER(:user)') - ->put(['user' => trim($key)]); + ->where('LOWER(name) = LOWER(?)')->put(trim($key)) + ->or('LOWER(email_confirmed) = LOWER(?)')->put(trim($key)); $row = Database::fetchOne($query); if ($row)