I have created this Entity :
<?php
namespace MyProject\MyBundle\Entity;
class User {
private $id;
function __construct($id) {
$this->id = $id;
}
public function setName($name) {
$sql = "UPDATE users SET name=:name WHERE id=:id";
$stmt = $this->connection->prepare($sql);
$stmt->execute(array('name' => '$name', 'id' => $this->id));
}
)
How can I connect to the database from it ?
I call this Entity from this controller :
<?php
namespace MyProject\MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use MyProject\MyBundle\Entity;
class MyController extends Controller {
public function indexAction() {
$user = new User(1);
$user->setName("Tom");
}
}