如何在使用LIKE的SQL语句中使用绑定值?

时间:2019-02-07 05:48:53

标签: php sqlite

{% for c in all_courses %}

{{c}}

{% endfor %}

此代码无效,因为显然//--------------------------------------------------------- public function searchCustomer($searchString) //--------------------------------------------------------- { $stmt = $this->prepare("SELECT cu_firstname, cu_lastname, id_customer FROM t_customers WHERE cu_firstname LIKE '%:token%' OR cu_lastname LIKE '%:token%' ;"); $stmt->bindValue(":token", $searchString, SQLITE3_TEXT); $result = $stmt->execute(); $data = array(); while ($row = $result->fetchArray(SQLITE3_ASSOC)){ $data[] = $row; } return $data; } 被忽略了。我发现使其起作用的唯一方法是在百分号之间直接使用:token

我该如何正确执行操作?或者此处不允许绑定参数?

2 个答案:

答案 0 :(得分:2)

在搜索字符串周围(而不是参数周围)添加%

    long long int n, a, b, k;
    std::cin >> n >> a >> b >> k;
    long long int na = n / a;
    long long int nb = n / b;
    long long int nab = n / (a * b);
    /*
    if (na + nb - 2 * nab >= k)
        std::cout << "Win\n";
    else
        std::cout << "Lose\n";*/
        std::cout<<(na+nb-2*nab);

答案 1 :(得分:1)

尝试一下:

 class Parent extends React.Component {
  constructor(props) {
    super(props)
    // without bind, replaced by arrow func below
  }

  handler = (val) => {
    this.setState({
      someVar: val
    })
  }

  render() {
    return <Child handler = {this.handler} />
  }
}

class Child extends React.Component {
  render() {
    return <Button onClick = {() => this.props.handler('the passing value')}/ >
  }
}