开发者

Why does insert from php to mysql mis-handle question marks sometimes, but from command line never?

I have a simple开发者_C百科 table:

describe chat_public_messageboard ;

    +--------------+---------------+------+-----+---------+----------------+
    | Field        | Type          | Null | Key | Default | Extra          |
    +--------------+---------------+------+-----+---------+----------------+
    | message_id   | int(100)      | NO   | PRI | NULL    | auto_increment |
    | message_from | varchar(255)  | NO   |     | NULL    |                |
    | message_to   | varchar(20)   | NO   |     | NULL    |                |
    | message_body | tinytext      | NO   |     | NULL    |                |
    | message_time | varchar(50)   | NO   |     | NULL    |                |
    | welcome_msg  | enum('0','1') | NO   |     | 0       |                |
    +--------------+---------------+------+-----+---------+----------------+

When I do an insert from the terminal, it works fine: select * 314 | sweety_margs | daffy | what did you say?

INSERT INTO chat_public_messageboard ( message_from , message_body , message_time , message_to , welcome_msg ) VALUES ( 'pdz' , 'what did you say?\n' , '1260948972' , 'pdz2' , 1 ) "

But when I send this exact query through the mysql db->query() function, the question mark turns to NULL

$query = $querystring = "INSERT INTO chat_public_messageboard ( message_from , message_body , message_time , message_to , welcome_msg ) VALUES ( 'pdz' , 'what did you say?\n' , '1260948972' , 'pdz2' , 1 ) " ;
db->query($querystring);

-

select *
    314 | sweety_margs  | daffy          | what did you sayNULL  

Thanks.


The ? is typically used as a placeholder for parametrized arguments in the PHP interface to various SQL. Thus, it's probably thinking it's a placeholder that you never specified a value for (and thus is NULL).


What PHP framework are you using? I'm suspecting that the framework is using '?' to bind parameters into your SQL statement and since you didn't provide the parameter it defaults to NULL.


It looks like it thinks you are trying to add a parameter to that query. What is the question mark's significance in MySQL at "WHERE column = ?"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜