我创建了这个实体:
<?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));
}
)
如何从它连接到数据库?
我从这个控制器调用这个实体:
<?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");
}
}