secret
Created

Entity

  • Download Gist
Log.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
/**
* @orm:Entity
*/
class Log {
 
/**
* @orm:Id
* @orm:Column(type="integer")
* @orm:generatedValue(strategy="AUTO")
*/
protected $id;
 
/**
* @orm:Column(name="created_at", type="datetime")
*/
protected $createdAt;
 
public function getId() {
return $this->id;
}
 
public function getCreatedAt() {
return $this->createdAt;
}
 
public function setCreatedAt(\DateTime $createdAt) {
$this->createdAt = $createdAt;
}
Test.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<?php
 
$createdAt = new \DateTime("now");
$em = $this->getEntityManager('default');
$log = $em->getRepository('Namespace\Log')->findOneBy(array('createdAt' => $createdAt));
 
/* I get this error
Catchable fatal error: Object of class DateTime could not be converted to string in D:\sites\localhost\vendor\doctrine-dbal\lib\Doctrine\DBAL\Connection.php on line 1050
 
Notice: Object of class DateTime to string conversion in D:\sites\localhost\vendor\doctrine-dbal\lib\Doctrine\DBAL\Connection.php on line 1050
 
Stack Trace:
 
1. in D:\sites\localhost\vendor\doctrine-dbal\lib\Doctrine\DBAL\Connection.php line 595
$stmt = $this->_conn->prepare($query);
if ($types) {
$this->_bindTypedValues($stmt, $params, $types);
$stmt->execute();
} else {
$stmt->execute($params);
}
 
2. at PDOStatement ->execute ()
 
3. at Connection ->executeQuery ('SELECT t0.id AS id1, t0.created_at AS created_at2 FROM Log t0 WHERE t0.created_at = ?', array(object(DateTime)), array('2'))
in D:\sites\localhost\vendor\doctrine\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php line 569
 
4. at BasicEntityPersister ->load (array('createdAt' => object(DateTime)))
in D:\sites\localhost\vendor\doctrine\lib\Doctrine\ORM\EntityRepository.php line 178
 
5. at EntityRepository ->findOneBy (array('createdAt' => object(DateTime)))
in D:\sites\localhost\src\Test.php line 95
gistfile2.sql
SQL
1 2 3 4 5 6 7 8
CREATE TABLE [dbo].[Log](
[id] [int] IDENTITY(1,1) NOT NULL,
[created_at] [datetime2](6) NOT NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.