-
-
Save AaronDDM/6b2a8b53ece6e75abf20 to your computer and use it in GitHub Desktop.
Entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment