dongzhong2018 2014-06-27 07:41
浏览 41
已采纳

INSERT INTO准备好的语句,PHP MYSQL,优化了很多专栏

Please help me to understand how to optimize mysql queries in php. When you have a lot of columns, prepared statement looks like

$inst = $db->prepare("insert into year_$year (user_name,type_of_day,month_row,day_1,day_2,day_3,day_4,day_5,day_6,day_7,day_8,day_9,
day_10,day_11,day_12,day_13,day_14,day_15,day_16,day_17,day_18,day_19,day_20,day_21,day_22,day_23,day_24,day_25,day_26,day_27,day_28,day_29,day_30,day_31)
values
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

$inst->execute($chunk_post[$init]);

this code is from here: http://govnokod.ru/php?page=356 where people ridicule shitty codes.

I do not understand how to do it in other way.

  • 写回答

3条回答 默认 最新

  • dswfyq6201 2014-06-27 08:17
    关注

    A little Joke:

    u can use for ($i = 1; $i <= 31; i++) {} to construct your Query ;)

    The Reality:

    Read about Database Normalization here: http://databases.about.com/od/specificproducts/a/normalization.htm

    Your Ultimate goal should be the third normal form.

    You should think about some Day which are linked to one Month.

    think about a table month and table day.

    Read about SQL JOIN.

    Sure, you will not have the DataType DateTime?

    This Question is way to broad to give you a solution instead of an learn here, learn there answer. Your Question is about basics.

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

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝