Fixes for MySQL driver

This commit is contained in:
Marcin Kurczewski 2013-12-18 17:49:22 +01:00
parent 9a9220ab24
commit 8cfc2aeb2a
3 changed files with 13 additions and 7 deletions

View file

@ -15,6 +15,7 @@ class Database
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 @@ class Database
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;
}

View file

@ -70,9 +70,8 @@ class PostEntity extends AbstractEntity
->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);

View file

@ -104,9 +104,8 @@ class UserModel extends AbstractCrudModel
$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)