Categories > OpenTBS with DOCX >

TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Grabin
Date: 2012-08-15
Time: 09:28

TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

Hello everyone.
I apologize for my English.
My PHP code is:

link to highlight syntaxis: http://pastebin.com/RBCqmD49

<?
// load the TinyButStrong libraries
if (version_compare(PHP_VERSION,'5')<0) {
    include_once('tbs_class_php4.php'); // TinyButStrong template engine for PHP 4
} else {
    include_once('tbs_class_php5.php'); // TinyButStrong template engine
}
// load the OpenTBS plugin
if (file_exists('tbs_plugin_opentbs.php')) {
    include_once('tbs_plugin_opentbs.php');
} else {
    include_once('../tbs_plugin_opentbs.php');
}
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin

//work with oracle
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = oci_parse($conn, 'SELECT department_name FROM departments');
oci_execute($stid);
while (($data = oci_fetch_array($stid, OCI_BOTH))) {
    // Use the uppercase column names for the associative array indices
    // echo $row[0] . " and " . $row['DEPARTMENT_ID']   . " are the same<br>\n";
    // echo $row[1] . " and " . $row['DEPARTMENT_NAME'] . " are the same<br>\n";
    var_dump($data);
}
oci_free_statement($stid);
oci_close($conn);
// Load the template
$TBS->LoadTemplate('example.docx', OPENTBS_ALREADY_UTF8);

// Merge data
$TBS->MergeBlock('a,b', $data);

// Define the name of the output file
$file_name = str_replace('.','_'.date('Y-m-d').'.',$template);
// Output as a download file (some automatic fields are merged here)
if ($debug==3) { // debug mode 3
    $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);
} elseif ($suffix==='') {
    // download
    $TBS->Show(OPENTBS_DOWNLOAD, $file_name);
} else {
    // save as file
    $file_name = "example.docx";
    $TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
?>

My DOCX code is one table with only one column:


Department Name
[a. department_name;block=w:tr]

When i start this code from GoogleChrome i see var_dump($data) like this:

array(2) { [0]=> string(14) "Administration" ["DEPARTMENT_NAME"]=> string(14) "Administration" } array(2) { [0]=> string(9) "Marketing" ["DEPARTMENT_NAME"]=> string(9) "Marketing" } array(2) { [0]=> string(10) "Purchasing" ["DEPARTMENT_NAME"]=> string(10) "Purchasing" } array(2) { [0]=> string(15) "Human Resources" ["DEPARTMENT_NAME"]=> string(15) "Human Resources" } array(2) { [0]=> string(8) "Shipping" ["DEPARTMENT_NAME"]=> string(8) "Shipping" } array(2) { [0]=> string(2) "IT" ["DEPARTMENT_NAME"]=> string(2) "IT" } array(2) { [0]=> string(16) "Public Relations" ["DEPARTMENT_NAME"]=> string(16) "Public Relations" } array(2) { [0]=> string(5) "Sales" ["DEPARTMENT_NAME"]=> string(5) "Sales" } array(2) { [0]=> string(9) "Executive" ["DEPARTMENT_NAME"]=> string(9) "Executive" } array(2) { [0]=> string(7) "Finance" ["DEPARTMENT_NAME"]=> string(7) "Finance" } array(2) { [0]=> string(10) "Accounting" ["DEPARTMENT_NAME"]=> string(10) "Accounting" } array(2) { [0]=> string(8) "Treasury" ["DEPARTMENT_NAME"]=> string(8) "Treasury" } array(2) { [0]=> string(13) "Corporate Tax" ["DEPARTMENT_NAME"]=> string(13) "Corporate Tax" } array(2) { [0]=> string(18) "Control And Credit" ["DEPARTMENT_NAME"]=> string(18) "Control And Credit" } array(2) { [0]=> string(20) "Shareholder Services" ["DEPARTMENT_NAME"]=> string(20) "Shareholder Services" } array(2) { [0]=> string(8) "Benefits" ["DEPARTMENT_NAME"]=> string(8) "Benefits" } array(2) { [0]=> string(13) "Manufacturing" ["DEPARTMENT_NAME"]=> string(13) "Manufacturing" } array(2) { [0]=> string(12) "Construction" ["DEPARTMENT_NAME"]=> string(12) "Construction" } array(2) { [0]=> string(11) "Contracting" ["DEPARTMENT_NAME"]=> string(11) "Contracting" } array(2) { [0]=> string(10) "Operations" ["DEPARTMENT_NAME"]=> string(10) "Operations" } array(2) { [0]=> string(10) "IT Support" ["DEPARTMENT_NAME"]=> string(10) "IT Support" } array(2) { [0]=> string(3) "NOC" ["DEPARTMENT_NAME"]=> string(3) "NOC" } array(2) { [0]=> string(11) "IT Helpdesk" ["DEPARTMENT_NAME"]=> string(11) "IT Helpdesk" } array(2) { [0]=> string(16) "Government Sales" ["DEPARTMENT_NAME"]=> string(16) "Government Sales" } array(2) { [0]=> string(12) "Retail Sales" ["DEPARTMENT_NAME"]=> string(12) "Retail Sales" } array(2) { [0]=> string(10) "Recruiting" ["DEPARTMENT_NAME"]=> string(10) "Recruiting" } array(2) { [0]=> string(7) "Payroll" ["DEPARTMENT_NAME"]=> string(7) "Payroll" }

And i have error:

TinyButStrong Error when merging block [Array]: the specified source is set to FALSE. Maybe your connection has failed.

TinyButStrong Error Show() Method: The output is cancelled by the OpenTBS plugin because at least one error has occured.

Is there anything I can do to resolve that?
Thanks a lot for your time!

kinds regards,
Grabin.
By: Skrol29
Date: 2012-08-15
Time: 12:19

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

Hi Grabin,

This is a simple error of logic.
In your snippet  $data is not a recordset but only the last record read.
The code leave the While loop when  $data is false.
So you're actually trying to merge the block with  $data=false.

You could check it by adding var_export($data) or var_dump($data) just before the MergeBlock().

Nevertheless, TBS should have say "TinyButStrong Error when merging block 'a,b'" instead of "TinyButStrong Error when merging block [Array]".


By: Grabin
Date: 2012-08-15
Time: 12:57

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

Hi Skrol29,
Thank you for your reply and explanation.

"You could check it by adding var_export($data) or var_dump($data) just before the MergeBlock()."
Indeed, in the end I have:
bool(false)

Can you help me to correctly adjust the code to work correctly?
All that is required of him is to insert an array into the column of the document docx.

Thanks a lot for your time!

kinds regards,
Grabin.
By: Grabin
Date: 2012-08-15
Time: 13:03

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

On a personal note I want to say thank you and express my respect for the author OpenTBS. Thanks to his efforts that we have a flexible tool for working with documents and not only. Thanks again, you're doing a great job!
Sincerely Grabin.
By: Skrol29
Date: 2012-08-15
Time: 13:31

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

oci_execute($stid);
$data = array();
while (($rec= oci_fetch_array($stid, OCI_BOTH))) {
  $data[] = $rec;
}

If you use PDO instead of direct Oracle extension, then it will be natively supported by TBS.
You could code directly
$TBS->MergeBlock('a,b', $pdo, "SELECT department_name FROM departments");

You can also try with the database plug-in for Oracle
http://www.tinybutstrong.com/plugins.php#plugin_db
By: Grabin
Date: 2012-08-15
Time: 13:57

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

Thanks again for your reply. I ask you again to give me a little of your time.
I rewrote the PHP code:
<?
// load the TinyButStrong libraries
if (version_compare(PHP_VERSION,'5')<0) {
    include_once('tbs_class_php4.php'); // TinyButStrong template engine for PHP 4
} else {
    include_once('tbs_class_php5.php'); // TinyButStrong template engine
}
// load the OpenTBS plugin
if (file_exists('tbs_plugin_opentbs.php')) {
    include_once('tbs_plugin_opentbs.php');
} else {
    include_once('../tbs_plugin_opentbs.php');
}
//load oracle plugin
if (file_exists('tbsdb_oracle.php')) {
    include_once('tbsdb_oracle.php');
}

$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin

//connect to DB
$conn = oci_connect('hr', 'welcome', 'localhost/XE');

// // Load the template
$TBS->LoadTemplate('example.docx', OPENTBS_ALREADY_UTF8);

// $TBS->MergeBlock
$TBS->MergeBlock('a,b', $conn, "SELECT department_name FROM departments");


// Define the name of the output file
$file_name = str_replace('.','_'.date('Y-m-d').'.',$template);
// Output as a download file (some automatic fields are merged here)
if ($debug==3) { // debug mode 3
    $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW);
} elseif ($suffix==='') {
    // download
    $TBS->Show(OPENTBS_DOWNLOAD, $file_name);
} else {
    // save as file
    $file_name = "example.docx";
    $TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}
?>
And got an error:

TinyButStrong Error in field [a.department_name...]: item 'department_name' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error Show() Method: The output is cancelled by the OpenTBS plugin because at least one error has occured.
By the way, the number of labels:      TinyButStrong Error in field [a.department_name...     equals the number of entries in the table. Namely - 27.

Thank you for your help again.
By: Grabin
Date: 2012-08-15
Time: 17:32

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

OK. At last I got inserted into the Word.

PHP code:
<?
// load the TinyButStrong libraries
if (version_compare(PHP_VERSION,'5')<0) {
    include_once('tbs_class_php4.php'); // TinyButStrong template engine for PHP 4
} else {
    include_once('tbs_class_php5.php'); // TinyButStrong template engine
}
// load the OpenTBS plugin
if (file_exists('tbs_plugin_opentbs.php')) {
    include_once('tbs_plugin_opentbs.php');
} else {
    include_once('../tbs_plugin_opentbs.php');
}
//load oracle plugin
if (file_exists('tbsdb_oracle.php')) {
    include_once('tbsdb_oracle.php');
}
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin
//connect to DB
$conn = oci_connect('hr', 'welcome', 'localhost/XE');
// // Load the template
$TBS->LoadTemplate('example.docx', OPENTBS_ALREADY_UTF8);

// $TBS->MergeBlock
$TBS->MergeBlock('a.b', $conn, "SELECT department_name FROM departments");

// save as file
$file_name = "example---.docx";
$TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
?>

But  I get a file (example---.docx) with a table of one column (rightly) that contains BLANK CELLS 8-O
The number of empty cells equals the number of records in the database of my query.
SELECT department_name FROM departments
How do I fix this?
By: Grabin
Date: 2012-08-16
Time: 01:23

Re: TinyButStrong Error when merging block [Array]: the specified source is set to FALSE.

All right! I did it!
Topic is closed.