0

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?


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;
}
1
  • the table name is not necessary before CONG, especially since you didn't use it before YMD_X. Commented Jul 27, 2010 at 18:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes,I am sure.Y tried to query the same SQL statement to query analyzer on Navicat for MySQL.
@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).
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.