Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php的问题';PDOS语句::执行/fetch/rowCount以测试数据库中是否存在值?_Php_Mysql_Validation_Pdo - Fatal编程技术网

使用php的问题';PDOS语句::执行/fetch/rowCount以测试数据库中是否存在值?

使用php的问题';PDOS语句::执行/fetch/rowCount以测试数据库中是否存在值?,php,mysql,validation,pdo,Php,Mysql,Validation,Pdo,我认为我的一门课有问题。在高层,我将向一个php文件发送一个表单,该文件将启动一个类。通过访问几个it方法,它可以确定数据库中是否存在值。如果是,则返回布尔值 以下是我认为是问题所在的代码: public function territoryCheck($numberOut) { $this->numberOut = $numberOut; //Execute test $this->checkConnect();

我认为我的一门课有问题。在高层,我将向一个php文件发送一个表单,该文件将启动一个类。通过访问几个it方法,它可以确定数据库中是否存在值。如果是,则返回布尔值

以下是我认为是问题所在的代码:

public function territoryCheck($numberOut)

    {

        $this->numberOut = $numberOut;



        //Execute test

        $this->checkConnect();

        $stmt = $this->dbh->prepare("SELECT t_id FROM Territory WHERE t_id = :param1");

        $stmt->bindParam(':param1', $this->numberOut);

        $stmt->execute();   
        $count = $stmt->rowCount();



        //Determine value of test

        if($count == 0)

        {

            return FALSE;

        }   

    }



    public function publisherCheck($lName, $fName)

    {

        $this->lName = $lName;

        $this->fName = $fName;



        //Execute test

        $this->checkConnect();

        $stmt = $this->dbh->prepare("SELECT p_id FROM People WHERE lastName = :param1 AND firstName = :param2");

        $stmt->bindParam(':param1', $this->lName);

        $stmt->bindParam(':param2', $this->fName);

        $stmt->execute();
        $count = $stmt->rowCount();



        //Determine value of test

        if($count == FALSE)

        {

            return FALSE;

        }

        else

        {

            $dummyvar = $stmt->fetch();

            $this->p_id = implode($dummyvar);

        }



    }



    public function isTerritoryOut($numberOut)

    {

        //Execute test

        $this->checkConnect();

        $this->numberOut = $numberOut;

        $stmt = $this->dbh->prepare("SELECT t_id FROM checkIn WHERE t_id = :param1");

        $stmt->bindParam(':param1', $this->numberOut);

        $stmt->execute();
        $count = $stmt->rowCount();



        //Determine value of test

        if($count != 0)

        {

            return TRUE;

        }   

    }
有三种方法,每种方法都是一个测试,将返回true或false。 我使用execute()、fetch()和最后的rowCount()进行测试,试图模拟我想要的值。两者似乎都不起作用。下面是调用这些方法的代码:

//Begin tests

    $checkOut->territoryCheck($numberOut);

    if($checkOut == FALSE)

    {

        $fail = "Territory number ".$numberOut." does not exist in our records. Please enter a valid territory. For more information, navigate to About.<\ br>";

    }



    $checkOut->publisherCheck($lName, $fName);

    if($checkOut == FALSE)

    {

        if($fail !== "")

            $fail .= "The publisher, ".$fName." ".$lName.", is not in our records. For more information, navigate to About.<\ br>";

        else

            $fail = "The publisher, ".$fName." ".$lName.", is not in our records. For more information, navigate to About.<\ br>";

    }



    $checkOut->isTerritoryOut($numberOut);

    if($checkOut === TRUE)

    {

        if($fail !== "")

            $fail .= "Territory number ".$numberOut." is currently checked out. Either the wrong number was entered or the territory hasn't been properly checked in.<\ br>";

        else

            $fail = "Territory number ".$numberOut." is currently checked out. Either the wrong number was entered or the territory hasn't been properly checked in.<\ br>";

    }
//开始测试
$checkOut->territoryCheck($numberrout);
如果($checkOut==FALSE)
{
$fail=“Territory number”。$numberRout.”在我们的记录中不存在。请输入有效的Territory。有关详细信息,请导航到关于。“;
}
$checkOut->publisherCheck($lName,$fName);
如果($checkOut==FALSE)
{
如果($fail!==“”)
$fail.=“发布者,$fName.”“$lName.”不在我们的记录中。有关详细信息,请导航到关于。“;
其他的
$fail=“发布者,.$fName.”$lName.”不在我们的记录中。有关详细信息,请导航到关于。“;
}
$checkOut->isteritoryout($numberrout);
如果($checkOut==TRUE)
{
如果($fail!==“”)
$fail.=“区域编号”$numberOut.”当前已签出。输入的编号错误或区域未正确签入。“;
其他的
$fail=“区域编号”$numberOut.”当前已签出。输入的编号错误或区域未正确签入。“;
}
为清楚起见,代码前面将fail设置为“”。发生的事情是,它经历了所有这些测试,就好像它们已经通过了一样,而我故意创造了本应该失败的情况。例如,我的数据库中只有地区编号1-130。如果我输入150,它基本上告诉我它存在

我不知道发生了什么,打字vs.=?,等等


感谢您的帮助$checkOut->publisherCheck();而不是
$test=$checkOut->publisherCheck();
。无论如何,它现在可以工作了