2

I am converting a php app to zend framework and utilizing Zend_Db_Table to make my queries. My problem is that after converting to zend format, my expected result for a text format field returns an empty string instead of the stored data.

A records with a text field length of 11000 always returns empty, however another record with 2500 length always returns correctly.

Is there something I need to configure? Is there a limit on the data that is returned using zend db table?

PHP MySQL using mysqli, returns true, var has value

$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$stmt= "select * from m_message where m.m_id='".$m_id."'";
$result = $db->query($q_message);

$result['m_content'] equals "I got a copy of the ..." (11000 characters / length)

Zend using pdo_mysql, returns true, var does not have value

$this->_db = Zend_Db_Table::getDefaultAdapter();
$stmt = $this->_db->query('SELECT m_content FROM m_message WHERE m_id = ? ', $messageId);
$result = $stmt->fetchAll();

$result['m_content'] equals (string)

$this->_db = Zend_Db_Table::getDefaultAdapter(); 
$stmt = $this->_db->select()->from('m_message', 'm_content')->where('m_id = ?',$messageId );
$result = $this->_db->fetchAll($stmt);

$result['m_content'] equals (string)

Update

Turns out it was appearing null while watching the variable while debugging in Netbeans. The var_dump of the variable actually showed the data, as expected. The problem was when I used the JSON helper to return the array as json. When looking at json_last_error(), it returned 5, JSON_ERROR_UTF8.

My DB Character Set is UTF-8, however to fix the problem I had to perform utf8_encode($result['m_content']) before passing it to the json helper :/

Dharman
  • 30,962
  • 25
  • 85
  • 135
steve
  • 1,786
  • 1
  • 15
  • 29
  • 2
    `Zend_Db_Adapter_Pdo_Mysql::fetchAll()` returns an array of results. Try a `var_dump` of `$result[0]['m_content']` and see if that has all the data you are looking for (assuming `$result` didn't return false). – drew010 Apr 16 '12 at 23:25
  • if i change to select *, var_dump shows values for all fields, except m_content. the above, each statement returns true. – steve Apr 16 '12 at 23:52
  • Ok strange, I am not sure what's going on, I haven't hit such a limitation in ZF and I have pulled text and data from columns using Zend_Db_Select that are in the megabyte size range. Are you using ZF 1.11.11 which is the latest version as of now? – drew010 Apr 16 '12 at 23:56
  • might not be a ZF problem, might be difference between using mysqli and PDO_mysql. Have you tried using the 'Mysqli' adapter? – RockyFord Apr 17 '12 at 06:28
  • I will try the mysqli adapter and see. SELECT * from the above shows all fields except the m_content text field. – steve Apr 18 '12 at 15:42
  • I just switched to mysqli adapter and I am getting the same result. Putting the exact query directly in Navicat/MySQL returns the record and all data :/ – steve Apr 18 '12 at 17:41
  • hmm, when I was debugging, the value was null, but just noticed that the var dump from the returned array VS a return JSON was different. The JSON obj is missing the value, but the actual var_dump of the array has it. – steve Apr 18 '12 at 18:31
  • dangit, looks like my problem was farther down the line with the JSON helper. After passing the array to the helper, $this->_helper->json($result), the m_content shows null in json. – steve Apr 18 '12 at 18:52

1 Answers1

0

To your last update, try this, so your connection is actually UTF-8.

$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$this->_db->query("SET NAMES 'utf8'");
Ronn0
  • 2,249
  • 2
  • 21
  • 36