Skip to content

@AaronDDM /Log.php secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Entity
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]
<?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;
}
<?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
Something went wrong with that request. Please try again.