Buenas, estoy empezando a desarrollar un portal en zend que conecta de dos bases de datos distintas: Una mysql (la principal) y una SqlServer (secundaria).
Antes de exponer mi error decir que la conexión a ambas bases de datos es correcta y soy capaz de ejecutar consultas en ambas con resultados positivos.
Mi problema empieza al crear el siguiente modelo de datos:
Código PHP:
Ver originalclass Application_Model_DbTable_Contact extends Zend_Db_Table_Abstract
{
protected $_name = 'Contact';
protected $_dbadapter = null;
public function init()
{
//load the other adapter
$registry=Zend_Registry::getInstance();
$session = $registry['session'];
$this->_dbadapter = $session->dbNav;
}
function fetchAll($where = null, $order = null, $count = null, $offset = null) {
// print_object($this->_dbadapter);
$this->_dbadapter->fetchAll();
}
Código PHP:
Ver originalclass Application_Model_Contact
{
public function __set($name, $value)
{
$method = 'set' . $name;
throw new Exception('Invalid user property');
}
$this->$method($value);
}
public function __get($name)
{
$method = 'get' . $name;
throw new Exception('Invalid user property');
}
return $this->$method();
}
public function getNo_() {
return $this->_No_;
}
public function setNo_($No_) {
$this->_No_ = (string) $No_;
return $this;
}
}
Código PHP:
Ver originalclass Application_Model_ContactMapper
{
protected $_dbTable;
public function setDbTable($dbTable)
{
$dbTable = new $dbTable();
}
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
}
public function getDbTable()
{
if (null === $this->_dbTable) {
$this->setDbTable('Application_Model_DbTable_Contact');
}
return $this->_dbTable;
}
// .....
public function fetchAll()
{
$resultSet = $this->getDbTable()->fetchAll();
foreach ($resultSet as $row) {
$entry = new Application_Model_Contact();
$entry->setName($row->Name);
$entries[] = $entry;
}
return $entries;
}
}
Y el error es el siguiente:
Exception information:
Message: [Microsoft][Administrador de controladores ODBC] Longitud de cadena o de b�fer no v�lida
Stack trace:
#0 C:\xampp\htdocs\Portal\library\Zend\Db\Statement.p hp(115): Zend_Db_Statement_Sqlsrv->_prepare(NULL)
#1 C:\xampp\htdocs\Portal\library\Zend\Db\Adapter\Sql srv.php(298): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Sqlsrv), NULL)
#2 C:\xampp\htdocs\Portal\library\Zend\Db\Adapter\Abs tract.php(478): Zend_Db_Adapter_Sqlsrv->prepare(NULL)
#3 C:\xampp\htdocs\Portal\library\Zend\Db\Adapter\Abs tract.php(736): Zend_Db_Adapter_Abstract->query(NULL, Array)
#4 C:\xampp\htdocs\Portal\application\models\DbTable\ Contact.php(20): Zend_Db_Adapter_Abstract->fetchAll()
#5 C:\xampp\htdocs\Portal\application\models\ContactM apper.php(61): Application_Model_DbTable_Contact->fetchAll()
#6 C:\xampp\htdocs\Portal\application\controllers\Use rsController.php(55): Application_Model_ContactMapper->fetchAll()
#7 C:\xampp\htdocs\Portal\library\Zend\Controller\Act ion.php(516): UsersController->userpageAction()
#8 C:\xampp\htdocs\Portal\library\Zend\Controller\Dis patcher\Standard.php(295): Zend_Controller_Action->dispatch('userpageAction')
#9 C:\xampp\htdocs\Portal\library\Zend\Controller\Fro nt.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#10 C:\xampp\htdocs\Portal\library\Zend\Application\Bo otstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#11 C:\xampp\htdocs\Portal\application\Bootstrap.php(8 0): Zend_Application_Bootstrap_Bootstrap->run()
#12 C:\xampp\htdocs\Portal\library\Zend\Application.ph p(366): Bootstrap->run()
#13 C:\xampp\htdocs\Portal\public\index.php(27): Zend_Application->run()
#14 {main}
Si podeis ayudarme os lo agradeceria, no tengo claro ni porque da el error, la llamada la hago asi:
Código PHP:
Ver original$contacts = new Application_Model_ContactMapper();
$this->view->contacts = $contacts->fetchAll();
como en los ejemplos de Zend oficiales