SQL Server主动拒绝Doctrine getRepository()

时间:2021-10-05 06:48:55

I am able to access the database though via pdo queries. Now I'm new to both of these things as I'm new to php, so I don't know which is preferred to use, but I assume an entity manager would be easier. My goal is to have a simple web application that can show data from an sql-server database.

我可以通过pdo查询访问数据库。现在我对这两件事情都很陌生,因为我是php的新手,所以我不知道哪个更适合使用,但我认为实体经理会更容易。我的目标是拥有一个简单的Web应用程序,可以显示来自sql-server数据库的数据。

System

系统

  • windows 8
  • 窗户8
  • php 7
  • PHP 7
  • sql-server pdo 4
  • sql-server pdo 4
  • symfony 3
  • symfony 3

Error message:

错误信息:

SQLSTATE[08001]: [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.

SQLSTATE [08001]:[Microsoft] [SQL Server的ODBC驱动程序13] TCP提供程序:无法建立连接,因为目标计算机主动拒绝它。

My code:

我的代码:

$repo = $em->getRepository('MyBundle:MyObject');

MyObject.php

MyObject.php

<?php
// src/MyBundle/Entity/MyObject.php

namespace MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * MyObject
 *
 * @ORM\Table(name="MyObject")
 * @ORM\Entity(repositoryClass="MyBundle\Repository\MyObjectRepository")
 */
class MyObject {
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=4)
     */
    private $type;
}

MyObjectRepository.php

MyObjectRepository.php

<?php
/**
 * Created by PhpStorm.
 * User: rsluimers
 * Date: 28-7-2017
 * Time: 10:55
 */

namespace MyBundle\Repository;

use Doctrine\ORM\EntityRepository;

class MyObjectRepository extends EntityRepository {

    public function create() {
        $entity = new MyObject();
        $entity->type('WM_B');
        $this->_em->persist($entity);
        $this->_em->flush();
    }
}

1 个解决方案

#1


0  

Check out the parameters file if everything is correct there:

如果一切正确,请查看参数文件:

database_host: localhost
database_port: port
database_name: database
database_user: user
database_password: pass

#1


0  

Check out the parameters file if everything is correct there:

如果一切正确,请查看参数文件:

database_host: localhost
database_port: port
database_name: database
database_user: user
database_password: pass