ERRO
PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nomecensurado.aluno' doesn't exist in C:\xampp\htdocs\alura\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:127
Stack trace:
#0 C:\xampp\htdocs\alura\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php(127): PDOStatement->execute(NULL)
#1 C:\xampp\htdocs\alura\vendor\doctrine\dbal\lib\Doctrine\DBAL\Statement.php(153): Doctrine\DBAL\Driver\PDOStatement->execute(NULL)
#2 C:\xampp\htdocs\alura\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(286): Doctrine\DBAL\Statement->execute()
#3 C:\xampp\htdocs\alura\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(1087): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->executeInserts()
#4 C:\xampp\htdocs\alura\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(400): Doctrine\ORM\UnitOfWork->executeInserts(Object(Doctrine\ORM\Mapping\ClassMetadata))
#5 C:\xampp\htdocs\alura\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php(37 in C:\xampp\htdocs\alura\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\AbstractMySQLDriver.php on line 42
Criar-aluno.php
<?php
use Alura\Doctrine\Entity\Aluno;
use Alura\Doctrine\Helper\EntityManagerFactory;
require_once __DIR__ . '/../vendor/autoload.php';
$aluno = new Aluno();
$aluno->setNome('Vinícius Dias');
$entityManagerFactory = new EntityManagerFactory();
$entityManager = $entityManagerFactory->getEntityManager();
$entityManager->persist($aluno);
$aluno->setNome('Vinicius Dias');
$entityManager->flush();
Aluno.php
<?php
namespace Alura\Doctrine\Entity;
/**
* @Entity
*/
class Aluno
{
protected $table = "aluno";
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
private $id;
/**
* @Column(type="string")
*/
private $nome;
public function getId(): int
{
return $this->id;
}
public function getNome(): string
{
return $this->nome;
}
public function setNome(string $nome): self
{
$this->nome = $nome;
return $this;
}
}
EntityManagerFactory.php (sim, troquei pelo mysql)
<?php
namespace Alura\Doctrine\Helper;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Setup;
class EntityManagerFactory
{
/**
* @return EntityManagerInterface
* @throws \Doctrine\ORM\ORMException
*/
public function getEntityManager(): EntityManagerInterface
{
$rootDir = __DIR__ . '/../Users';
$config = Setup::createAnnotationMetadataConfiguration(
[$rootDir . '/src'],
true
);
$connection = [
'driver' => 'pdo_sqlite',
'path' => $rootDir . '/var/data/banco.sqlite'
];
$connectionParams = array(
'dbname' => 'censurado',
'user' => 'root',
'password' => '',
'host' => 'localhost',
'driver' => 'pdo_mysql',
);
return EntityManager::create($connectionParams, $config);
}
}
isso só acontece com mysql