Categories > TinyButStrong general >

PDO error

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: klepy
Date: 2008-01-22
Time: 19:04

PDO error

Hi,

maybe it is something simple, but i cannot get it working until now:
I am trying to connect to a mssql database using PDO in from a webserver in XP with php525. I would like to try using PDO, because in the future i would like to migrate to a different database ;)

This works fine:

$dns='mssql:host=localhost;dbname=calls';
$user='root';
$pass='sa';

try {
   $dbh= new PDO($dns,$user,$pass);
} catch (PDOException $e) {
   echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SELECT * FROM contactos";
    foreach ($dbh->query($sql) as $row)
        {
        print $row['name'] .' - '. $row['phone'] . '<br />';
        }



but changing it to use TBS like this:

include_once('../lib/tbs/tbs_class5.php');
include_once('../lib/tbs/tbsdb_pdo.php');

$dns='mssql:host=localhost;dbname=calls';
$user='root';
$pass='sa';

try {
   $dbh= new PDO($dns,$user,$pass);
} catch (PDOException $e) {
   echo 'Connection failed: ' . $e->getMessage();
}

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('./test_tbspdo.html') ;
$TBS->MergeBlock('blk',$dbh,'SELECT * FROM contactos') ;
$TBS->Show() ;
produces an error page saying:
PDO DB Error: "(null) [0] (severity 0) []" on query "SELECT * FROM contactos"

TinyButStrong Error when merging block [blk] : function tbsdb_PDO_open() has failed to open query {SELECT * FROM contactos}
[blk.name;block=tr]    [blk.phone]
Now i am not sure if i am missing some parameter somewhere or if it is an issue of this beta version.
Thanks if someone could give me a hint on how to proceed.

Thank You.
By: TomH
Date: 2008-01-22
Time: 19:18

Re: PDO error

Just guessing mind you... looks like you're getting the connection, but not getting a query result.

Try something to see if there's a result set. Like
include_once('../lib/tbs/tbs_class5.php');
include_once('../lib/tbs/tbsdb_pdo.php');

$dns='mssql:host=localhost;dbname=calls';
$user='root';
$pass='sa';

try {
   $dbh= new PDO($dns,$user,$pass);
} catch (PDOException $e) {
   echo 'Connection failed: ' . $e->getMessage();
}

// add an actual query...
$result=$dbh->query('SELECT * FROM contactos');

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('./test_tbspdo.html') ;

//$TBS->MergeBlock('blk',$dbh,'SELECT * FROM contactos') ;
$TBS->MergeBlock('blk',$result) ; // use just the result set
//$TBS->MergeBlock('blk','array',$result) ; // may need array param

$TBS->Show() ;


Then you can test also the result set in the template
<pre>[var.result]</pre>
By: klepy
Date: 2008-01-22
Time: 19:32

Re: PDO error

Thanks TomH,

i tried this, but i get an error page saying:
TinyButStrong Error when merging block [blk] : Data source Id 'PDOStatement' is unsupported because function 'tbsdb_PDOStatement_open' is not found.
.. And yes i think the database connection is working, it is probably just some issue with the processing for display.