我用 ExtJS 和 PHP 创建了一个搜索工具。PHP 文件是与数据库通信的服务器端脚本。在我的 Linux 环境中,它可以完美运行。但是,由于我需要在 Windows Server 上安装此应用程序,因此我尝试将其复制到我的个人 Windows XP 中。
我安装了 Apache、带有必要扩展的 PHP 和 MySQL。登录屏幕加载并且身份验证工作。当您通过身份验证时,应用程序会成功加载数据(数据是有关人员的信息;身份证等...)。
每当我尝试搜索时都会出现问题。当我在 Linux 环境中搜索时,它正在工作,现在 Firebug 向我显示以下错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'am' in 'where clause'
我没有任何列'am'。与此最相似的是 NAME 列。我尝试从 php 文件中删除代码块以隔离问题,但一切都是徒劳的。
你知道为什么搜索不能在 Windowos 上运行,而是在 Linux 上运行吗?
这是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);
}
此代码是来自 ExtJS 的示例。我修改了很多。但是,我认为问题的根源来自 getWhere 函数。但是,我尝试将其删除,但代码仍然存在。
在过去的 24 小时里,我一直在努力解决这个问题。我发现的唯一“解决方案”是创建具有重复字段的数据库。原因如下:
ExtJS表单第一次加载时,列是正确的,即name,idcard等...每当我开始搜索时,列名的第一个和最后一个字母都消失了,这意味着它们变成了这样:am,dcar等。 ..
我所做的是为 name、idcard 等创建重复列...将它们命名为 am、dcar 等...
我知道这是很多重复的数据,但我不明白为什么这只发生在 Windows 上!糟透了!
非常感谢