当字段值以数字开头时,db Query失败

时间:2016-03-30 01:50:11

标签: php mysql angularjs slim

我遇到了一个有趣的问题。我正在使用Angular与PHP Slim和Mysql。由于数据库中有一列,我的选择查询失败。列是uid,它是varchar(110)。

它充满了唯一的ID,有些以字母开头,有些以数字开头。我已经得出结论,当我使用以数字开头的uid删除行时,它可以工作。

注意:我在运行MAMP的本地计算机上没有此问题。

Slim可以解释字段错误吗?若有,那么有谁知道如何解决这个问题。我根本不懂Slim

编辑:

require '.././libs/Slim/Slim.php';
require_once 'dbHelper.php';

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app = \Slim\Slim::getInstance();
$db = new dbHelper();

// stats
$app->get('/stats', function() { 
    global $db;
    $rows = $db->select("trackclicks","id,action,platform,value,firstname,lastname,email,uid,timeclicked",array());
echoResponse(200, $rows);
});

**HELPER FILE**  
function select($table, $columns, $where){
    try{
        $a = array();
        $w = "";
        foreach ($where as $key => $value) {
            $w .= " and " .$key. " like :".$key;
            $a[":".$key] = $value;
        }
        $stmt = $this->db->prepare("select ".$columns." from ".$table." where 1=1 ". $w);
        $stmt->execute($a);
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        if(count($rows)<=0){
            $response["status"] = "warning";
            $response["message"] = "No data found.";
        }else{
            $response["status"] = "success";
            $response["message"] = "Data selected from database";
        }
            $response["data"] = $rows;
    }catch(PDOException $e){
        $response["status"] = "error";
        $response["message"] = 'Select Failed: ' .$e->getMessage();
        $response["data"] = null;
    }
    return $response;
}

0 个答案:

没有答案