Здравствуйте. Только начал осваивать работу с БД используя PDO и видимо все еще чтото не понимаю. У меня в базе есть таблица Problem и в ней поле problemdescription. Далее есть вот такой код PHP: require_once 'regestries\ApplicationRegistry.php'; abstract class Mapper { protected static $PDO; function __construct() { if(!isset(self::$PDO)) { $dsn = ApplicationRegistry::getDSN(); $request= RequestRegistry::getRequest(); $login = $request->getProperty('login'); $pass=$request->getProperty('password'); if(is_null($dsn)) { throw new Exception("DSN не определен"); } self::$PDO = new PDO($dsn,$login,$pass); self::$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } } function find($id) { $this->selectStmp()->execute(array($id)); $array= $this->selectStmp()->fetch(); $this->selectStmp()->closeCursor(); if(!is_array($array)) {return NULL;} if(!isset($array['id'])) {return NULL;} $object= $this->createObject($array); return $object; } function createObject($array) { $obj = $this->createObject($array); return $obj; } function insert(DomainObject $obj) { $this->doInsert($obj); } abstract function update(DomainObject $object); protected abstract function doCreateObject(array $array); protected abstract function doInsert(DomainObject $object); protected abstract function selectStmp(); } PHP: class ProblemMapper extends Mapper{ function __construct() { parent::__construct(); $this->selectStmp= self::$PDO->prepare("SELECT * from problem where id =?"); $this->updateStmt= self::$PDO->prepare( "UPDATE problem set problemdescription=? where id=?"); $this->insertStmt = self::$PDO->prepare("INSERT into problem (problemdescription) values(?)"); } function getCollection(array $raw) { return new ProblemCollection($raw, $this); } protected function doCreateObject(array $array) { $obj = new Problem($array['id']); $obj->setProblemDescription($array['problemdescription']); return $obj; } protected function doInsert(\DomainObject $object) { $values = array($object->getProblemDescription()); $this->insertSmtp->execute($values); $id = self::$PDO->lastInsertId(); $object->setId($id); } protected function selectStmp() { return $this->selectStmp(); } public function update(\DomainObject $object) { $values = array($object->getProblemDescription(),$object->getId()); $this->updateSmtp->execute($values); } } Вызываю его так PHP: $request = ViewHelper::getRequest(); $fio = $request->getProperty('fio'); print_r('Добро пожаловать!!! '. $fio); $mapper = new ProblemMapper(); $probl1 = $mapper->find(1); print_r($probl1); После выполнения код выдает мне вот такую чушь PHP: #0 C:\xampp\htdocs\PhpProject2\Mapper.php(28): PDO->__construct('mysql:host=loca...', 'ang', '123456') #1 C:\xampp\htdocs\PhpProject2\ProblemMapper.php(17): Mapper->__construct() #2 C:\xampp\htdocs\PhpProject2\views\SaccusessAutorization.php(22): ProblemMapper->__construct() #3 C:\xampp\htdocs\PhpProject2\PageController.php(29): include('C:\\xampp\\htdocs...') #4 C:\xampp\htdocs\PhpProject2\PageControllerManager.php(49): PageController->forward('views\\Saccusess...') #5 C:\xampp\htdocs\PhpProject2\index.php(29): PageControllerManager->process() #6 {main} Эти классы конечно используются у меня но почему они вдруг начали выводится то ?? Там просто должно выдастся значение колонки problemdescription
Хмм проблема вот в этом месте PHP: $dsn = 'mysql:dbname=mybase;host=localhost'; $login='ang'; $pass='123456'; self::$PDO = new PDO($dsn,$login,$pass); Я уже в ручную указал логин пароль и дсн но все тоже самое почему то ((
разобрался. Дошло что надо было поймать ошибку try catch ем оказалось что пользователя то я в таблицу юзеров занес но права на работу в базе не дал