Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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
读取sql脚本时不运行php脚本_Php_Mysql - Fatal编程技术网

读取sql脚本时不运行php脚本

读取sql脚本时不运行php脚本,php,mysql,Php,Mysql,我的php脚本有问题。该脚本从mysqli数据库中读取数据,然后将其保存到数组中供以后使用。在我想插入更多的sql语句以保持我的mysli表(从中获取数据)最新之前,该脚本工作得很好 我使用前三行连接到数据库并运行sql脚本。没有他们一切都好 <?php $con=mysqli_connect('localhost', 'root', '','mks-solution-dev'); $sqlSource = file_get_contents('Einrichtung.sql'); my

我的php脚本有问题。该脚本从mysqli数据库中读取数据,然后将其保存到数组中供以后使用。在我想插入更多的sql语句以保持我的mysli表(从中获取数据)最新之前,该脚本工作得很好

我使用前三行连接到数据库并运行sql脚本。没有他们一切都好

<?php

$con=mysqli_connect('localhost', 'root', '','mks-solution-dev');
$sqlSource = file_get_contents('Einrichtung.sql');
mysqli_multi_query($con,$sqlSource);

$categories = Category::getTopCategories();
$categories = array_values($categories);
echo json_encode($categories);

    // Here, the entries in $data are indexed by the values they also have in                  'name'
// If you want them numerically indexed, all you have to do is:
//$data = array_values($data);
//echo json_encode(array('data' => $data));
//echo json_encode($data);      

class Category
{
    /**
     * The information stored in the database for each category
     */
    public $id;
    public $parent;
    public $name;
    public $vlink;      

    // The child categories
    public $children;

    public function __construct()
    {
        // Get the child categories when we get this category
        $this->getChildCategories();
    }

    /**
     * Get the child categories
     * @return array
     */
    public function getChildCategories()
    {
        if ($this->children) {
            return $this->children;
        }
        return $this->children = self::getCategories("parent = {$this->id}");
    }
    ////////////////////////////////////////////////////////////////////////////

    /**
     * The top-level categories (i.e. no parent)
     * @return array
     */
    public static function getTopCategories()
    {
        return self::getCategories('parent = 0');
    }

    /**
     * Get categories from the database.
     * @param string $where Conditions for the returned rows to meet
     * @return array
     */
    public static function getCategories($where = '')
    {
        if ($where) $where = " WHERE $where";
        $conn=mysqli_connect('localhost', 'root', '','mks-solution-dev');
        mysqli_set_charset($conn,"UTF8"); 


        $sql = "SELECT * FROM mdl_praktikum$where";         
        print $sql;         

        $result =mysqli_query($conn,$sql);
        print $result;

        $categories = array();
        while ($category = mysqli_fetch_object($result, 'Category'))
           {
        $vlink = array('vlink' => $category->vlink);
        unset($category->vlink);
        $category->data = $vlink;
        $categories[] = $category;
       }

        mysqli_free_result($sqlSource);
        mysqli_free_result($result);
        return $categories;
    }
}
?>
其中一些没有:

SELECT * FROM mdl_praktikum WHERE parent = 0 

SELECT * FROM mdl_praktikum WHERE parent = 1 

SELECT * FROM mdl_praktikum WHERE parent = 2 

SELECT * FROM mdl_praktikum WHERE parent = 3 

SELECT * FROM mdl_praktikum WHERE parent = 6 
.
.
.
SELECT * FROM mdl_praktikum WHERE parent = 386 

SELECT * FROM mdl_praktikum WHERE parent = 387 

SELECT * FROM mdl_praktikum WHERE parent = 388 

[{"id":"1","parent":"0","name":"root","children":[{"id":"2","parent":"1","name":"Verschiedenes","children":[],"ref":"1","layer":"1","data":{"vlink":null}},{"id":"3","parent":"1","name":"EBSN","children":[{"id":"6","parent":"3","name":"EBSN 1415","children":[{"id":"23","parent":"6","name":"General .......

我想在我的方法getCategories的某个地方出现了完全错误,但我不明白为什么

MySQL!=SQL Server请不要滥用代码段工具。它应该只用于HTML/JS/CSS。听起来好像SQL脚本正在从表中删除数据。SQL脚本中有什么?您正在编写自己的ORM吗?若然,原因为何?在你继续沿着这条路往前走之前,你应该先看看。我怀疑这会鼓励人们创建间隙,因为它不支持占位符值。是的,脚本会删除该表,然后再次创建该表,并用其他表中的信息填充该表。其中总共有8条语句。
SELECT * FROM mdl_praktikum WHERE parent = 0 

SELECT * FROM mdl_praktikum WHERE parent = 1 

SELECT * FROM mdl_praktikum WHERE parent = 2 

SELECT * FROM mdl_praktikum WHERE parent = 3 

SELECT * FROM mdl_praktikum WHERE parent = 6 
.
.
.
SELECT * FROM mdl_praktikum WHERE parent = 386 

SELECT * FROM mdl_praktikum WHERE parent = 387 

SELECT * FROM mdl_praktikum WHERE parent = 388 

[{"id":"1","parent":"0","name":"root","children":[{"id":"2","parent":"1","name":"Verschiedenes","children":[],"ref":"1","layer":"1","data":{"vlink":null}},{"id":"3","parent":"1","name":"EBSN","children":[{"id":"6","parent":"3","name":"EBSN 1415","children":[{"id":"23","parent":"6","name":"General .......