Skip to content

Commit

Permalink
Fixes for MySQL driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kurczewski committed Dec 18, 2013
1 parent 9a9220a commit 8cfc2ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Models/Entities/PostEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8cfc2ae

Please sign in to comment.