tags:

views:

31

answers:

2

I queried:

select * 
  from marrydays 
 where YMD_X like '2010-1-%' 
   and marrydays.CONG not like 'aa%' 
   and marrydays.CONG not like 'bb%' ;

But after I use mysql_fetch_object function,I didn't got exact result,the result just like I queried :

select * from marrydays where YMD_X like '2010-1-%' ;

Why?

+1  A: 

Since PHP's mysql_query function just passes things to MySQL as you wrote them, are you sure that running the same query directly on MySQL gives a different result?

The problem here almost certainly lies with your query.

Borealid
Yes,I am sure.Y tried to query the same SQL statement to query analyzer on Navicat for MySQL.
CatWin
@Catwin : then show us your PHP, please.
Borealid
Ok,some pieces:
CatWin
@Catwin : First off, just edit your question to add additional information. That's not an answer you posted. Second, don't terminate your queries with semicolons when you're using `mysql_query`; it handles all that. Thirdly, you've got non-Anglo-Saxon characters in there. Didn't you think that was important enough to mention? Make sure your MySQL charset and collation settings are the same in PHP as they are from the command line you used to test. Finally, are you sure the `find` is doing what you want? As written, it will only ever return one row when `!empty($key)`.
Borealid
Sorry ,I am new here!About this question,I am sure about:1.The characters encoding is correct.2.I just used semicolons for terminate a whole queries.3.The function was perfect working. When I queried the SQL statement , the returns only matching one "like",one "not like" .it seems the last "not like" statement wasn't useful.
CatWin
A: 

Some code pieces:

$res1 = $db->find("select * from marrydays where YMD_X like"." '".$cnDate."%' and CONG not like '冲".$male_shu."%' ;");

public function find($sql, $key=null){ $data = array(); $result = $this->query($sql); while($row = mysql_fetch_object($result)){ if(!empty($key)){ $data[$row->{$key}] = $row; }else{ $data[] = $row; } } return $data; }

public function query($sql){
    $stime = microtime(true);

    $result = mysql_query($sql, $this->conn);
    $this->query_count ++;
    if($result === false){
        throw new Exception(mysql_error($this->conn)." in SQL: $sql");
    }

    $etime = microtime(true);
    $time = number_format(($etime - $stime) * 1000, 2);
    $this->query_list[] = $time . ' ' . $sql;
    return $result;
}
CatWin