Categories > OpenTBS general >

TinyButStrong Error when merging block

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Mhd
Date: 2014-04-17
Time: 12:03

TinyButStrong Error when merging block

i use TBS for the first time and i truly need help i used the demo and tried to modify the class demo_ms_excel.php to test but i got this Error:

TinyButStrong Error when merging block [a]: MySql error message when opening the query: No database selected

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

here is my simple code:
<?php
// Create connection
$con=mysqli_connect("localhost","root","","vb");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Include classes
include_once('tbs_class.php'); // Load the TinyButStrong template engine
include_once('../tbs_plugin_opentbs.php'); // Load the OpenTBS plugin

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


$template = 'demo_ms_excel.xlsx';
$TBS->LoadTemplate($template); // Also merge some [onload] automatic fields (depends of the type of document).

$TBS->MergeBlock('a','vb','SELECT * FROM thread');


// -----------------
// Output the result
// -----------------

// Define the name of the output file
$save_as = (isset($_POST['save_as']) && (trim($_POST['save_as'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['save_as']) : '';
$output_file_name = str_replace('.', '_'.date('Y-m-d').$save_as.'.', $template);
if ($save_as==='') {
    // Output the result as a downloadable file (only streaming, no data saved in the server)
    $TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields.
} else {
    // Output the result as a file on the server
    $TBS->Show(OPENTBS_FILE+TBS_EXIT, $output_file_name); // Also merges all [onshow] automatic fields.
}
mydata base name is vb table name is : thread column : title that i used it in the .xlsx file [a.title]
By: Skrol29
Date: 2014-04-17
Time: 12:53

Re: TinyButStrong Error when merging block

Hi Mhd,

The problem is this line:
$TBS->MergeBlock('a','vb','SELECT * FROM thread');
Instead of 'vb' you have to give the connexion to the MySQM database. That can be a PHP MySQL ressource, or PDO object, or a Zend FRamework object.