I want to save static data values into php myadmin database table, with symfony. but when I used to run my save route, it shows an error:
An exception occurred in driver: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
My table with name article and fields are created successfully.
TestController.php
<?php
namespace AppController;
use AppEntityArticle;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class TestController extends AbstractController
{
/**
* @Route("/save")
*/
public function save(): Response{
$entitymanager = $this->getDoctrine()->getManager();
$article = new Article();
$article->setTitle('Test');
$article->setBody('This is the test');
$entitymanager->persist($article);
$entitymanager->flush();
return new Response('Saved');
}
}
Article.php
<?php
namespace AppEntity;
use AppRepositoryArticleRepository;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass=ArticleRepository::class)
*/
class Article
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="text", length=20)
*/
private $title;
/**
* @ORMColumn(type="text")
*/
private $body;
public function getId()
{
return $this->id;
}
public function getTitle(){
return $this->title;
}
public function getBody(){
return $this->bdoy;
}
public function setTitle($title){
$this->title = $title;
}
public function setBody($body){
$this->body = $body;
}
}
question from:
https://stackoverflow.com/questions/65920375/unable-to-save-static-data-using-symfony 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…