简体   繁体   中英

mysql_query returns true when executing joined UPDATE query

I am creating a script in PHP that updates my users, user_personal and user_extra table in MySQL using joins. When i execute the query using mysql_query it returns true, but the tables are not updated.

I've read online that mysql_query return false if it fails or a MySQL resource if it succeeds, and also read that this is a known bug by PHP .

This is the query in question.

UPDATE users
        INNER JOIN user_personal
        ON users.id = user_personal.id
        INNER JOIN user_extra
        ON users.id = user_extra.id
        SET
        users.email                      = '" . $user->email . "',              
        user_extra.life_condition        = '" . $user->life_condition . "',
        user_extra.keycode               = '" . $user->keycode . "',
        user_extra.contact_person_phone  = '" . $user->contact_person_phone . "',
        user_extra.doctor                = '" . $user->doctor . "',
        user_extra.doctor_phone          = '" . $user->doctor_phone . "',
        user_extra.doctorpost_phone      = '" . $user->doctorpost_phone . "',
        user_extra.condition             = '" . $user->condition . "',
        user_extra.allergy               = '" . $user->allergy . "',
        user_extra.goal                  = '" . $user->goal . "',
        user_extra.attention_officer     = '" . $user->attention_officer . "',
        user_extra.primary_respon        = '" . $user->primary_respon . "',
        user_personal.name               = '" . $user->name . "',
        user_personal.last_name          = '" . $user->last_name . "',
        user_personal.insertion          = '" . $user->insertion . "',
        user_personal.birthdate          = '" . $user->birthdate . "',
        user_personal.sex                = '" . $user->sex . "',
        user_personal.street_name        = '" . $user->street_name . "',
        user_personal.house_number       = '" . $user->house_number . "',
        user_personal.postal_code        = '" . $user->postal_code . "',
        user_personal.city               = '" . $user->city . "',
        user_personal.country            = '" . $user->country . "',
        user_personal.tel_nr             = '" . $user->tel_nr . "',
        user_personal.contact_person     = '" . $user->contact_person . "'
        WHERE user_personal.name         = '" . $user->name . "'

When I executed a smaller test version of the query using one INNER JOIN the function returned a resource, same results when i do the query without joins. My server uses PHP 5.3.3 and Apache version 2.2.15 with MySQL server 5.1.69.

Can you explain how this happens? And is there a solution for this problem?

I've read the documentation on PHP.net and learned when using INSERT, UPDATE, DELETE, DROP the method returns true or false

When using SELECT, SHOW, DESCRIBE, EXPLAIN you get an resource when the query is successful and false when the query failed.

Thanks for the comments guys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM