简体   繁体   English

基于ExtJS的基于php的搜索工具在Windows环境下无法正常工作

[英]A php-based search facility with ExtJS not working well on Windows Environment

I created a search facility with ExtJS and PHP. 我使用ExtJS和PHP创建了一个搜索工具。 The PHP file is the server side script with communicates with the database. PHP文件是与数据库通信的服务器端脚本。 On my Linux Environment, its working flawlessly. 在我的Linux环境中,它可以完美运行。 However, since I need to install this application on a Windows Server, I tried to copy it to my personal Windows XP. 但是,由于需要在Windows Server上安装此应用程序,因此我尝试将其复制到个人Windows XP中。

I installed Apache, PHP with the necessary extensions, and MySQL. 我安装了Apache,具有必要扩展的PHP和MySQL。 The logon screen loads and the authentication works. 登录屏幕将加载,并且身份验证有效。 When you are authenticated, the application loads the data successfully (the data is information about people; idcard, etc...). 通过身份验证后,应用程序将成功加载数据(数据是有关人的信息;身份证等)。

The problem occurs whenever I try to search. 每当我尝试搜索时,就会出现问题。 When I searched on the Linux envirnoment, it was working, now Firebug shows me the following error: 当我搜索Linux环境时,它正在运行,现在Firebug向我显示以下错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'am' in 'where clause'

I don't have any column 'am'. 我没有“ am”列。 The most similar to this is the NAME column. 与此最相似的是“名称”列。 I tried removing chunks of code from the php file to isolate the problem but all was in vain. 我试图从php文件中删除代码块以隔离问题,但一切都是徒劳的。

Do you have any idea why the search is not working on Windowos but its working on Linux? 您是否知道为什么搜索不能在Windowos上进行而在Linux上可以进行?

Here is the code for the php file: 这是php文件的代码:

function regexp($search, $value) {
// case insensitive hard coded
return @preg_match("/$search/i", $value); 
}

function concat_ws() {
    $args = func_get_args();
    $sep = array_shift($args);
    return implode($sep, $args);
} // eo function concat_ws

 function quote_array(&$val, $key, $quot = '"') {
    $quot_right = array_key_exists(1, (array) $quot) ? $quot[1] : $quot[0];
    $val = is_null($val) ? "null" : $quot[0] . preg_replace("/'/", "''", $val) .    $quot_right;
}

class csql {

public function getLastTable() {

$sql  = "SELECT table_name, create_time FROM information_schema.TABLES WHERE table_schema = 'mydbname' ORDER BY CREATE_TIME desc LIMIT 1";

$ostmt = $this->odb->query($sql);
$tableArray = $ostmt->fetchAll(PDO::FETCH_OBJ);

$table = $tableArray[0]->table_name;

return $table;

}

// protected functions
protected function getOdb($engine) {
    switch($engine) {
        case "sqlite":
            if("/" !== $file[0]) {
                $file = realpath(".") . "/$file";
            }
            $odb = new PDO("sqlite:$file");
            $odb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $odb->sqliteCreateFunction("regexp", "regexp", 2);
            $odb->sqliteCreateFunction("concat_ws", "concat_ws");
        break;

        case "mysql";
            $hostname = 'localhost';
            $username = 'myuser';
            $password = 'mypass';
            $odb = new PDO("mysql:host=$hostname;dbname=mydbname", $username, $password);
            $odb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        break;
    }

    return $odb;
} 

protected function getWhere($params) {

    $where = isset($where) ? "where $where" : "";

    $query = "";

    if($query && is_array($search) && sizeof($search)) {
        $a = array();
        foreach($search as $f) {
            $a[] = "$f regexp '$query'";
        }
        $where .= $where ? " and(" : "where (";
        $where .= implode(" or ", $a) . ")";
    }

    return $where;

} 

public function __construct($engine = "mysql") {
    $this->odb = $this->getOdb($engine);
} 

public function getCount($params) {

    // params to variables
    extract($params);

    $selectedFields = $_POST['fields'];

    $selectedFields = explode(",", $selectedFields);


    $count = 0;
    foreach ($selectedFields as $selectedField)
    {

        if ($count == 0)
        {
            $selectedField = substr_replace($selectedField, "", 0, 3);
            $selectedField= substr_replace($selectedField, "", -2);

            $selectedFields[0] = $selectedField;
        }

        else if ($count == count($selectedFields)-1)
        {
            $selectedField = substr_replace($selectedField, "", 0, 2);
            $selectedField = substr_replace($selectedField, "", -3);

            $selectedFields[count($selectedFields)-1] = $selectedField;
        }
        else
        {
            $selectedField = substr_replace($selectedField, "", 0, 2);
            $selectedField = substr_replace($selectedField, "", -2);

            $selectedFields[$count] = $selectedField;
        }

        $count++;
    }

    if ($count == 1)
    {
        $selectedFields[0] = substr_replace($selectedFields[0], "", -1);
    }

    if ($_POST['fields'] == "")
    {
        $like = "";
        foreach ($fields as $field)
        {
            $like = $like . $field . " LIKE '%" . $query . "%' or ";    

        }
        $like = substr_replace($like, "", -3);

    }
    else
    {
        $queryExploded = explode(" ", $query);

        $fullLike = "";

        foreach ($queryExploded as $explode)
        {
            foreach ($selectedFields as $selectedField)
            {
                $fullLike = $fullLike . " " . $selectedField . " LIKE '%" . $explode . "%' OR ";
            }

            $fullLike = substr_replace($fullLike, ") AND (", -3);

        }
        $fullLike = substr_replace($fullLike, "", -5);

    }

    $count = null;

    if ($_POST['fields'] == "")
    {
        $ostmt = $this->odb->prepare("select count(*) from {$params['table']} " . $this->getWhere($params));
    }
    else
    {
        $ostmt = $this->odb->prepare("select count(*) from {$params['table']} where (" . $fullLike . $this->getWhere($params));
    }

    $ostmt->bindColumn(1, $count);
    $ostmt->execute();
    $ostmt->fetch();
    return (int) $count;

} 

public function getData($params) {

    $fullLike = "";
    // params to variables
    extract($params);
    $selectedFields = $_POST['fields'];
    $selectedFields = explode(",", $selectedFields);

    $count = 0;
    foreach ($selectedFields as $selectedField)
    {

        if ($count == 0)
        {
            $selectedField = substr_replace($selectedField, "", 0, 3);
            $selectedField= substr_replace($selectedField, "", -2);

            $selectedFields[0] = $selectedField;
        }
        else if ($count == count($selectedFields)-1)
        {
            $selectedField = substr_replace($selectedField, "", 0, 2);
            $selectedField = substr_replace($selectedField, "", -3);

            $selectedFields[count($selectedFields)-1] = $selectedField;
        }
        else
        {
            $selectedField = substr_replace($selectedField, "", 0, 2);
            $selectedField = substr_replace($selectedField, "", -2);

            $selectedFields[$count] = $selectedField;
        }
        $count++;
    }

    if ($count == 1)
    {
        $selectedFields[0] = substr_replace($selectedFields[0], "", -1);
    }

    if ($_POST['fields'] == "")
    {
        $like = "";
        foreach ($fields as $field)
        {
            $like = $like . $field . " LIKE '%" . $query . "%' or ";    

        }
        $like = substr_replace($like, "", -3);  
    }
    else
    {
        $queryExploded = explode(" ", $query);

        $fullLike = "";

        foreach ($queryExploded as $explode)
        {
            foreach ($selectedFields as $selectedField)
            {
                $fullLike = $fullLike . " " . $selectedField . " LIKE '%" . $explode . "%' OR ";
            }

            $fullLike = substr_replace($fullLike, ") AND (", -3);

        }

        $fullLike = substr_replace($fullLike, "", -5);
    }

    $sql  = "select * ";
    //$sql .= implode(",", $fields);
    if ($fullLike == "")
    {
        $sql .= " from $table";
    }
    else
    {
        $sql .= " from $table where  (" . $fullLike . $this->getWhere($params);
    }
    $sql .= isset($groupBy) && $groupBy ? " group by $groupBy" : "";

    if(!is_null($sort)) {
        $sql .= " order by $sort";
        $sql .= is_null($dir) ? "" : " $dir";
    }
    if(!is_null($start) && !is_null($limit)) {
        $sql .= " limit $start,$limit";
    }


    $ostmt = $this->odb->query($sql);

    return $ostmt->fetchAll(PDO::FETCH_OBJ);

}

This code was a sample from ExtJS. 这段代码是ExtJS的示例。 I modified it a lot. 我做了很多修改。 However, I though the source of the problem was from the getWhere function. 但是,尽管问题的根源来自getWhere函数。 However, I tried removing it and the code still remained there. 但是,我尝试将其删除,但代码仍保留在那里。

I have been struggling for the last 24 hours with this problem. 在过去的24小时里,我一直在努力解决这个问题。 The only 'solution' I found was to create the database with duplicate fields. 我发现的唯一“解决方案”是创建具有重复字段的数据库。 Here is the reason: 原因如下:

When the ExtJS form first loads, the columns are correct, ie name, idcard, etc... Whenever I start searching, the first and last letter of the column name disappears, which means they become like this: am, dcar, etc... 当首次加载ExtJS表单时,列是正确的,即名称,身份证等。每当我开始搜索时,列名称的第一个和最后一个字母都会消失,这意味着它们变为:am,dcar等。 ..

What I've done is to create duplication columns for name, idcard, etc... naming them am, dcar, etc... 我要做的是为名称,身份证等创建重复列...将它们命名为am,dcar等...

I know this is a lot of duplication of data but I cant understand why this is happening only on Windows! 我知道这是很多重复数据,但我不明白为什么这仅在Windows上发生! It sucks! 糟透了!

Many Thanks 非常感谢

Do some code isolation to narrow down the problem. 进行一些代码隔离以缩小问题范围。

Create a new PHP file. 创建一个新的PHP文件。 Copy ONLY the search code into it. 将搜索代码复制到其中。 Run the php file through your browser (not the extjs code). 通过浏览器运行php文件(而不是extjs代码)。 Does it fail the same way? 它会以同样的方式失败吗?

Since it works on Linux and not on Windows, could it be a file encoding issue? 由于它可以在Linux上运行,而不能在Windows上运行,是否可能是文件编码问题? A server configuration issue? 服务器配置问题? Are both Windows and Linux pointing to the same database? Windows和Linux是否都指向同一个数据库?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM