致命错误:在非对象上调用成员函数bindParam()

时间:2012-10-09 11:57:33

标签: php class sqlbindparameter member-functions

  

可能重复:
  Fatal error: Call to a member function bindParam()

有人可以帮我修复我的剧本,因为我真的不知道出了什么问题。它工作得很好,直到我添加了多种语言。

这是我选择和阅读轮胎的脚本:

            <div id="bloklinks">
<?php
    include_once "class/tekst.class.php";
    $teksten = new tekst($dbo);
    $tekst = $teksten->getTeksten($website, $lang, $_GET['p']);
?>
                <h3><?php 
                    if(isset($_POST['searchtyre']) && $_POST['type'] != "type" || isset($_POST['searchtyre']) && $_POST['size'] != "size" || isset($_GET['type']) && isset($_GET['app']))
                    {
                        $searchinfo = new search($dbo);
                        $splittype = array("0","");
                        if(isset($_POST['type']) && $_POST['type'] != "type")
                        {
                            $splittype = split("-", $_POST['type']);
                        }
                        $type = isset($_GET['type']) ? $_GET['type'] : $splittype[0];
                        $splittype[1] = isset($splittype[1]) ? $splittype[1] : 0;
                        $app = isset($_GET['app']) ? $_GET['app'] : $splittype[1];
                        $size = NULL;
                        $typearray = $searchinfo->getTypes($website, $type);
                        $apparray = $searchinfo->getApplications($website, $type, $app);
                        echo "<span>";
                        if($type != 0){ echo " >> ".$typearray[0]->type_naam; }
                        if(isset($apparray[0])){ echo " >> ".$apparray[0]->application_naam; }
                        if(isset($_POST['size']) && $_POST['size'] != "size" || isset($_GET['size']) && $_GET['size'] != "size") 
                        { 
                            $size = isset($_GET['size']) ? $_GET['size'] : $_POST['size'];
                            echo " >> ".$size; 
                        } 
                        echo "</span>";
                    }
                    else
                    {
                        echo "Products"; 
                    } ?>&nbsp;</h3>
                <div class="hr"><hr/></div>
                <div id="bandentabel">
                    <table cellspacing="0">
                        <tr>
<?php
include_once "class/banden.class.php";
    $banden = new banden($dbo);
    if(isset($_POST['type']) && $_POST['type'] == "type" && $_POST['size'] == "size")
    {
        echo "\t\t\t\t\t\t\t<th colspan=\"2\" style=\"font-size: 12px; font-weight: normal;\">Please select a type & application or a size.</th>\n";
        $bandlijst = array();
    }
    else if(isset($type) && isset($app))
    {
        $app = ($app == 0) ? $app = NULL : $app = $app;
        $bandlijst = $banden->getBanden($website, NULL, $type, $app, $size);
        if(count($bandlijst) == 0)
        {
            echo "\t\t\t\t\t\t\t\t<th style=\"font-size: 12px; font-weight: normal;\">Company doesn't have a ".$typearray[0]->type_naam." ";
            if(isset($apparray[0])){ echo $apparray[0]->application_naam." "; }
            echo $size." inch tyre in her program, please select a different size.</th>\n";
        }
        $app = ($app == NULL) ? $app = 0 : $app = $app;
    }
    else
    {
        if(isset($size))
        {
            $bandlijst = $banden->getBanden($website, NULL, NULL, NULL, $size);
        }
        else
        {
            $bandlijst = $banden->getBanden($website);
        }
    }
    $counter = 0;
    $patternarray = array();
    foreach($bandlijst as $band)
    {
        if(!in_array($band->band_ID, $patternarray))
        {
            if($counter == 2)
            {
                echo "\t\t\t\t\t\t</tr>
\t\t\t\t\t\t<tr>\n";
                $counter = 0;
            }
            if(isset($type) && isset($app))
            {
                echo "\t\t\t\t\t\t\t<td><a href=\"?lang=".$_GET['lang']."&amp;p=2&amp;type=".$type."&amp;app=".$app;
                if(isset($size))
                {
                    echo "&amp;size=".$size;
                }
                echo "&amp;b=".$band->band_ID."#specification\"><img src=\"bestanden/banden/".$band->band_imgnaam."-K.png\" width=\"107\" height=\"23\" alt=\"".$band->band_pattern."\"><p>".$band->band_pattern."<br/><span>Specification</span></p></a></td>\n";
            }
            else if(isset($size))
            {
                echo "\t\t\t\t\t\t\t<td><a href=\"?lang=".$_GET['lang']."&amp;p=2&amp;type=0&amp;app=0&amp;size=".$size."&amp;b=".$band->band_ID."#specification\"><img src=\"bestanden/banden/".$band->band_imgnaam."-K.png\" width=\"107\" height=\"23\" alt=\"".$band->band_pattern."\"><p>".$band->band_pattern."<br/><span>Specification</span></p></a></td>\n";
            }
            else
            {   
                echo "\t\t\t\t\t\t\t<td><a href=\"?lang=".$_GET['lang']."&amp;p=2&amp;b=".$band->band_ID."#specification\"><img src=\"bestanden/banden/".$band->band_imgnaam."-K.png\" width=\"107\" height=\"23\" alt=\"".$band->band_pattern."\"><p>".$band->band_pattern."<br/><span>Specification</span></p></a></td>\n";
            }
            $counter++;
            array_push($patternarray, $band->band_ID);
        }
    }
    if($counter == 1)
    {
        echo "\t\t\t\t\t\t\t\t<th>&nbsp;</th>\n";
    }
?>
                        </tr>
                    </table>
                </div>
            </div>
<?php
    <div id="blokrechts">
                <h3>Tyre search</h3>
                <div class="hr"><hr/></div>
                <form action="?lang=<?php echo $_GET['lang'];?>&amp;p=2" method="post">
<?php
    $seltype = 0;
    $application = 0;
    $size = 0;
    $search = new search($dbo);
    if(isset($_POST['searchtyre']) && $_POST['type'] != "type" || isset($_POST['searchtyre']) && $_POST['size'] != "size" || isset($_GET['type']) && isset($_GET['app']))
    {
        $splittype = array("0","");
        if(isset($_POST['type']) && $_POST['type'] != "type") { $splittype = split("-", $_POST['type']); }
        $seltype = isset($_GET['type']) ? $_GET['type'] : $splittype[0];
        if($seltype == "type") { $seltype = 0; }
        $splittype[1] = isset($splittype[1]) ? $splittype[1] : 0;
        $application = isset($_GET['app']) ? $_GET['app'] : $splittype[1];
        $size = NULL;
        if(isset($_POST['size']) && $_POST['size'] != "size" || isset($_GET['size']) && $_GET['size'] != "size") { $size = isset($_GET['size']) ? $_GET['size'] : $_POST['size']; }
    }
?>
                    <table class="searchtable">
                        <tr>
                            <td>
                                <select name="type">
                                    <option value="type">-- Type &amp; Application --</option>
<?php
    $types = $search->getTypes($website);
    foreach($types as $type)
    {
        $selected = "";
        $applications = $search->getApplications($website, $type->type_ID);
        if(count($applications) > 0)
        {
            echo "\t\t\t\t\t\t\t\t\t<optgroup label=\"".$type->type_naam."\">\n";
            foreach($applications as $app)
            {
                $selected = "";
                if($application == $app->application_ID) { $selected = " selected=\"selected\""; }
                echo "\t\t\t\t\t\t\t\t\t\t<option value=\"".$type->type_ID."-".$app->application_ID."\"".$selected.">".$app->application_naam."</option>\n";
            }
            echo "\t\t\t\t\t\t\t\t\t</optgroup>\n";
        }
        else
        {
            if($type->type_ID == $seltype) { $selected = " selected=\"selected\""; }
            echo "\t\t\t\t\t\t\t\t\t<option value=\"".$type->type_ID."\"".$selected.">".$type->type_naam."</option>\n";
        }
    }               
?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <select name="size">
                                    <option value="size">-- Size --</option>
<?php
    $inchlist = $search->getSizes($website);
    sort($inchlist);
    $doublelist = array();
    foreach($inchlist as $inch)
    {
        $selected = "";
        if(!in_array($inch->bandinfo_size, $doublelist))
        {
            if($size == $inch->bandinfo_size) { $selected = " selected=\"selected\""; }
            array_push($doublelist, $inch->bandinfo_size);
            echo "\t\t\t\t\t\t\t\t\t<option value=\"".$inch->bandinfo_size."\"".$selected.">".$inch->bandinfo_size."</option>\n";
        }
    }
?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="submit" name="searchtyre" value="Search" />
                            </td>
                        </tr>
                    </table>
                </form>

                <h3>Contact us</h3>
                <div class="hr"><hr/></div>
                <table class="contacttable">
                    <tr>
                        <td class="itemtekst">Phone:</td>
                        <td>+31 12345678</td>
                    </tr>
                    <tr>
                        <td class="itemtekst">Fax:</td>
                        <td>+31 12345678</td>
                    </tr>
                    <tr>
                        <td class="itemtekst">E-mail:</td>
                        <td>info@email.com</td>
                    </tr>
                </table>
            </div>

?>
            <div class="clearboth">&nbsp;</div>
            <!--<a name="specification"></a>//-->
<?php
if(isset($_GET['b']))
{
    $headwaarde = $banden->getBanden($website, $_GET['b']);
?>
            <div id="matentabel">
                <table id="spectabel">
                    <tr>
                        <td rowspan="4" class="bandafb">
                            <a href="#" onclick="fx.changeImage('<?php echo $headwaarde->band_imgnaam; ?>', this); return false;">
                                <img src="afbeeldingen/vergroot.png" width="14" height="13" alt="vergroot/verklein" class="zoom"/>
                                <img src="bestanden/banden/<?php echo $headwaarde->band_imgnaam; ?>.png" width="206" height="260" alt="<?php echo $headwaarde->band_pattern; ?>"/>
                            </a>
                        </td>
                        <th><?php echo $headwaarde->band_pattern; ?></th>
                    </tr>
                    <tr>
                        <td style="padding-bottom: 10px;"><?php echo $headwaarde->band_text; ?></td>
                    </tr>
                    <tr>
                        <td><img src="afbeeldingen/specification.png" width="9" height="9" alt="specification"/>&nbsp;&nbsp;Specification</td>
                    </tr>
                    <tr>
                        <td>
                            <div>
                                <table class="spec">
                                    <tr>
<?php
    switch($headwaarde->band_type)
    {
        case "1":
        case "3":
        default:
?>
                                        <th>Item Code</th>
                                        <th>Tire Size</th>
                                        <th>Load Symbol</th>
                                        <th>Note</th>
                                        <th>Speed Max (KM/H)</th>
                                        <th>Overall Diameter (mm)</th>
                                        <th>Section Width (mm)</th>
                                        <th>Tread Depth (mm)</th>
                                        <th>Rim Width (inch)</th>
                                        <th>Weight (KGS)</th>
                                        <th>Single MAX load / pressure (KGS/PSI)</th>
                                        <th>Brandstof</th>
                                        <th>Geluid Db</th>
                                        <th>Geluid</th>
                                        <th>Grip</th>
<?php
            break;
        case "2":
?>
                                        <th>Item Code</th>
                                        <th>Tire Size</th>
                                        <th>Load Index (S/D)</th>
                                        <th>Ply Rating</th>
                                        <th>SI</th>
                                        <th>Overall Diameter (mm)</th>
                                        <th>Section Width (mm)</th>
                                        <th>Tread Depth (mm)</th>
                                        <th>Rim Width (inch)</th>
                                        <th>Weight (KGS)</th>
                                        <th>Single MAX load / pressure (KGS/PSI)</th>
                                        <th>Dual MAX load / pressure (KGS/PSI)</th>
                                        <th>Brandstof</th>
                                        <th>Geluid Db</th>
                                        <th>Geluid</th>
                                        <th>Grip</th>
<?php
            break;
    }
?>
                                    </tr><?php

    $bandinfo = $banden->getBandenInfo($website, $headwaarde->band_ID);

    foreach($bandinfo as $banditem)
    {
        switch($headwaarde->band_type)
        {
            case "1":
            case "3":
            default:
                echo "\n\t\t\t\t\t\t\t\t\t<tr>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_itemcode."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_size."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_loadsymbol."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_note."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_speedmax."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_overalldiameter."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_sectionwidth."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_treaddepth."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_rim."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_weight."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_singlemax."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_fuel."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_geluid_db."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_geluid_img."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_grip."</td>
\t\t\t\t\t\t\t\t\t</tr>";
                break;
            case "2":
                echo "\n\t\t\t\t\t\t\t\t\t<tr>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_itemcode."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_size."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_loadindex."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_plyrating."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_speedsymbol."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_overalldiameter."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_sectionwidth."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_treaddepth."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_rim."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_weight."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_singlemax."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_dualmax."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_fuel."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_geluid_db."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_geluid_img."</td>
\t\t\t\t\t\t\t\t\t\t<td>".$banditem->bandinfo_grip."</td>
\t\t\t\t\t\t\t\t\t</tr>";
                break;
        }
    }
    echo "\n";
?>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
<?php
}
?>

这是我连接到我的数据库的类:

<?php
include_once "connect.class.php";

class banden extends connect
{   

    private $bandenlijst;

    private $bandinfolijst;

    public function getBanden($database, $pattern = NULL, $type = NULL, $app = NULL, $size = NULL)
    {
        $sql = "SELECT * FROM `".$database."_banden`";

        if(!empty($pattern))
        {
            $sql .= " WHERE band_ID=:pattern LIMIT 1";
        }
        else if(!empty($type))
        {
            if(!empty($size))
            {
                $sql .= " INNER JOIN _bandinfo ON bandinfo_pattern=band_ID";
            }
            $sql .= " WHERE band_type LIKE :type";
            if(!empty($app))
            {
                $sql .= " AND band_application LIKE :app";
            }
            if(!empty($size))
            {
                $sql .= " AND bandinfo_size=:size";
            }
        }
        else if(!empty($size))
        {
            $sql .= " INNER JOIN ".$database."_bandinfo ON bandinfo_pattern=band_ID WHERE bandinfo_size=:size";
        }
        else
        {
            $sql .= " ORDER BY band_ID DESC";
        }
        try
        {
            $stmt = $this->db->prepare($sql);
            if(!empty($pattern))
            {
                $stmt->bindParam(":pattern", $pattern, PDO::PARAM_STR);
            }
            if(!empty($type))
            {
                $type = $type;
                $stmt->bindParam(":type", $type, PDO::PARAM_INT);
                if(!empty($app))
                {
                    $app = $app;
                    $stmt->bindParam(":app", $app, PDO::PARAM_STR);
                }
            }
            if(!empty($size))
            {
                $stmt->bindParam(":size", $size, PDO::PARAM_STR);
            }
            $stmt->execute(); 
            $this->bandenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
            $stmt->closeCursor();

            if(!empty($pattern) && isset($this->bandenlijst[0]))
            {
                $this->bandenlijst = $this->bandenlijst[0];
            }

            return $this->bandenlijst;
        }
        catch (Exception $e)
        {
            die ($e->getMessage());
        }
    }

public function getBandeninfo($database, $pattern=NULL, $id = NULL, $limit = NULL)
    {
        $sql = "SELECT * FROM ".$database."_bandeninfo";
        if(!empty($id))
        {
            if(is_numeric($id))
            {
                $sql .= " WHERE bandinfo_ID=:id LIMIT 1";
            }
            else
            {
                return NULL;
            }
        }
        else if(!empty($pattern) && is_numeric($pattern))
        {
            $sql .= " WHERE bandinfo_pattern=:pattern";
        }
        if(empty($id) && !empty($limit))
        {
            if($limit == 1) { $limit = 0; }
            $sql .= " LIMIT ".$limit.", 15";
        }
        try
        {
            $stmt = $this->db->prepare($sql);
            if(!empty($id) && is_numeric($id))
            { 
                $stmt->bindParam(":id", $id, PDO::PARAM_INT); 
            }
            else if(!empty($pattern) && is_numeric($pattern))
            {
                $stmt->bindParam(":pattern", $pattern, PDO::PARAM_INT);
            }
            $stmt->execute();
            $result = $stmt->fetchAll(PDO::FETCH_OBJ);
            $stmt->closeCursor();

            return $result;
        }
        catch(Exception $e)
        {
            die($e->getMessage());
        }
    }

    public function __construct($dbo = NULL)
    {

        parent::__construct($dbo);
    }
}
?>

以下是可怕的错误:

当我在第一次下拉中选择一些东西时,提交它一切都很好......

但是当我添加一个大小时,我收到了这个错误:

致命错误:在第62行的/website.com/class/banden.class.php中的非对象上调用成员函数bindParam()

第62行= $stmt->bindParam(":size", $size, PDO::PARAM_STR);

取决于我的选择......有时是这一行:

$stmt->bindParam(":type", $type, PDO::PARAM_INT);

有人能帮助我吗?我不认为自己在自己修理它:(

非常感谢你

0 个答案:

没有答案