Categories > TinyButStrong general >

Tbssql call fails but I can't see why.

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Don Bledsoe
Date: 2009-09-04
Time: 01:53

Tbssql call fails but I can't see why.

This isn't working, but I can't see why. Here's the code:
include_once('inc/tbssql_mysql.php');
$Db = new clsTbsSQL('$srv="localhost",$uid="xxxxxx",$pwd="xxxxxx",$db="xxxxxx"');
$Db->Connect($srv,$uid,$pwd,$db);
$Db->Mode = 3;

function saveWord($wordtext) {
   //    Insert into MySQL database
   $Db->Execute('INSERT INTO words (word) VALUES (@1@)',$word);
   return;
}

//    Create arrays of consonants and vowels

$consonants = array('b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z','ch','cl','cr','fl','fr','gl','gr','pl','pr','qu','sc','sl','sm','sn','sp','sq','st','sw','tr','tw','wh','wr');
$vowels     = array('a','e','i','o','u','y','aa','ae','ai','ao','au','ay','ea','ee','ei','eo','eu','ey','ia','ie','io','iu','iy','oa','oe','oi','oo','ou','ua','ue','ui','uo','uu','ya','ye','yi','yo','yu','yy');

$vowelsCount    = 38;
$consonantsCount    = 41;

//    Begin web page
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD/ XHTML 1.0 Transitional //EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3c.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <titleRandom Word Builder</title>
    <style type="text/css">
    <!--
    body { font-family: Verdana; font-size: 10px; font-weight: normal; }
    H1 { font-family: Arial; font-size: 14px; font-weight: bold; }
    -->
    </style>
</head>
<body>
<H1>Random Word Builder</H1>
<br><br>

<?php
//    Build words
$word = "";
//    1st letter
for($cntLetter1=0; $cntLetter1<=$consonantsCount; $cntLetter1++) {
   $Letter1 = $consonants[$cntLetter1];
   for($cntLetter2=0; $cntLetter2<=$vowelsCount; $cntLetter2++) {
      $Letter2 = $vowels[$cntLetter2];
      for($cntLetter3=0; $cntLetter3<=$consonantsCount; $cntLetter3++) {
         $Letter3 = $consonants[$cntLetter3];
         $word = $Letter1.$Letter2.$Letter3;
         echo $word."<br>";
         saveWord($word);
         for($cntLetter4=0; $cntLetter4<=$vowelsCount; $cntLetter4++) {
            $Letter4 = $vowels[$cntLetter4];
            $word .= $Letter4;
            echo $word."<br>";
            saveWord($word);
         }
      }
   }
   $word = "";
}
?>
</body>
</html>

This is displayed on the screen:
[TbsSql] Automatic Connection: global variable '$srv="localhost",$uid="wrdbldr",$pwd="C&ampF=Tu5",$db="wrdbldr"' is not found.
[TbsSql] Database error message: Access denied for user 'ODBC'@'localhost' (using password: NO)

Random Word Builder

bab

Fatal error: Call to a member function Execute() on a non-object in C:\xampp\htdocs\WordBuilder\wordbuilder.php on line 22

I think it fails when the saveWord function is called. It acts like the class is not instantiated, but it looks like it is, to me. Can anyone see what I'm doing wrong?
By: Skrol29
Date: 2009-09-04
Time: 09:30

Re: Tbssql call fails but I can't see why.

Hi Don,

You are not passing four arguments to the class instantiation, but only one because of the string delimiter.

Replace
$Db = new clsTbsSQL('$srv="localhost",$uid="xxxxxx",$pwd="xxxxxx",$db="xxxxxx"');
with:
$Db = new clsTbsSQL($srv="localhost",$uid="xxxxxx",$pwd="xxxxxx",$db="xxxxxx");
By: Don Bledsoe
Date: 2009-09-04
Time: 13:44

Re: Tbssql call fails but I can't see why.

Oh I see.

Now I only get the last error:  Fatal error: Call to a member function Execute() on a non-object in C:\xampp\htdocs\WordBuilder\wordbuilder.php on line 22

$Db->Execute('INSERT INTO words (word) VALUES (@1@)',$word);

I tried this:
$Db->Execute('INSERT INTO words (word) VALUES (@1@)',$wordtext);
... but it failed again, so I think I have a syntax error, but the statement seems to be correct.
By: Skrol29
Date: 2009-09-04
Time: 14:07

Re: Tbssql call fails but I can't see why.

It means that $Db is not an object. It has not been instantiated. Check your code and variables names.
By: Don Bledsoe
Date: 2009-09-05
Time: 05:36

Re: Tbssql call fails but I can't see why.

This is not instantiating and I do not know why:
include_once('inc/tbssql_mysql.php');
$Db = new clsTbsSQL($srv='',$uid='',$pwd='',$db='',$drv='');
$Db->Mode = 3;
This is copied and pasted from the manual. I get this error:
Fatal error: Call to a member function Execute() on a non-object in C:\xampp\htdocs\WordBuilder\wordbuilder.php on line 22

Clearly it is not happening and I'm completely at a loss as to what to do next.
By: Skrol29
Date: 2009-09-05
Time: 05:40

Re: Tbssql call fails but I can't see why.

Hi,

The $Db variable used in your function saveWord() is a local variable. It is a different variable from the other $Db that you have instantiated.
You have to define $Db as global and refers to it as global in the function, or pass the variable as an argument of the function.
By: Don Bledsoe
Date: 2009-09-05
Time: 20:07

Re: Tbssql call fails but I can't see why.

Dedclaring $Db global did the trick.

THANK YOU!