MySQL查询既不是真也不是假

时间:2018-01-09 11:34:26

标签: php mysql

我有一个代码,用于从表操作符中选择某些行。连接成功但是当我运行代码时,我既不是真也不是假。 neither fail message nor successful

这是表格 the Operators table

注意:将$ class更改为“PushCrew”是故意的。

此外,如果我必须获取数组中的值,那么执行此任务的更好/最佳方法是什么?

       <?php

$servername = "localhost";
$username = "root";
$password = "indicadls02";
$database = "segmentor";
$conn = new mysqli($servername, $username, $password, $database);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "Connected successfully <br>";

error_reporting(-1);

class gang {

    private $operators;

    public function fetchOperators() {
        $class = get_class($this);
        echo "$class <br>";
        $class = "PushCrew";
        $que = "select * from Operators where Tag = '$class' ";
        echo "$que <br>";
        if(mysqli_num_rows(mysqli_queri($conn, $que)) > 0) {
            echo "query is true <br>";
            $operators = $conn->query($que);
            print_r($operators);
        }
        else {
            echo "select query failed <br>";
        }
    }

    public function getOperators() {
        $this->operators = $this->fetchOperators();
        if(get_parent_class($this)) {
            echo "parent exists <br>";
            echo "$this->operators OPS <br>";
            $parent = get_parent_class($this);
            $temp = new $parent();
            $operatorsInherited = $temp->getOperators();
            echo "$operatorsInherited  inherited<br>";
            $this->operators += ($operatorsInherited);
        }
        else {
            echo "tree finished <br>";
        }
        return $this->operators;
    }
}

class bang extends gang{
    private $operators;
};

$ob2 = new bang();
$ob2->fetchOperators();
//$arr = $ob2->getOperators();
//print_r($arr);

2 个答案:

答案 0 :(得分:1)

我认为这是错误的

mysqli_queri

使用mysqli_query()

更正此问题

答案 1 :(得分:0)

我做了一些改动,现在它有效。 1.在课外发布时,数据库连接无效。 2.正如@ Gjord83在回答中提到的那样,我纠正了这个错误。

这是最终版本(忽略其他功能):

<?php

error_reporting(-1);

$con = mysqli_connect("127.0.0.1","root","indicadls02","segmentor");

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

class PushCrew {

    private $operators;

    public function fetchOperators() {
        echo "inside fetchOperators <br>";
        $con = mysqli_connect("127.0.0.1","root","indicadls02","segmentor");
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        $operators = mysqli_query($con,"SELECT * FROM Operators");
        print_r($operators);
        echo "<br>";
    }

    public function getOperators() {
        $this->fetchOperators();
        if(get_parent_class($this)) {
            echo "parent exists <br>";
            $parent = get_parent_class($this);
            $temp = new $parent();
            $operatorsInherited = $temp->getOperators();
            //$operators = array_merge($operatorsInherited);
        }
        else {
            echo "tree finished <br>";
        }
    }

    public function convertConditionToJsCode() {

    }
    public function getJsCode($partialSegments) {
        if (! count($partialSegments)) {
            return null;
        }


    }
}

class ClickEvent extends PushCrew{
    private $operators;
};


$ob2 = new ClickEvent();
$arr = $ob2->getOperators();
print_r($arr);