dtm41506 2014-06-29 15:37
浏览 28
已采纳

使用PHP将SET元素插入mysql db表

Let just say I have table in my mysql db called Film. It has a film_id which is id column and special_features column which is of type SET. Never used SET type before. Special_features column is of type set('Trailers', 'Commentaries', 'behind'),

I want to enter this row in the table:

SET("trailers", "commentaires", "behind the scenes");

How should my basic sql command look like in php? I am using MySQLi and I want basic sql string.

$sql = "INSERT INTO (special_features) VALUES (('trailers', 'commentaires', 'behind the scenes'))";

how would my sql string look like if I want only trailers and commentaries inserted?

This is just example, not sure if it is correct?

  • 写回答

3条回答 默认 最新

  • dongyan3616 2014-06-29 18:26
    关注

    I suppose it will be something like this:

    $sql = "INSERT INTO set_field(special_features) VALUES('trailers,commentaires')";
    

    Here is another example with all Film table columns:

    INSERT INTO `film`(`title`, `description`, `release_year`, `language_id`, `original_language_id`, `rental_duration`, `rental_rate`, `length`, `replacement_cost`, `rating`, `special_features`) VALUES ('blade','cutting vampires','1998',1,1,0.4,4.99,120,60,0.8, ('Trailers,Commentaries,Deleted Scenes,Behind the Scenes'))
    

    However you must be careful with the values separated by comma. There shouldn't be a whitespace between and all values must be exact match(all characters upper and lower case) as when the table was created.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件