How to put mysql inside a php function?

后端 未结 6 1053
梦谈多话
梦谈多话 2021-01-14 15:37

I have problem about putting mysql into a function showMsg(). The mysql is working fine if it is not wrapped by function showMsg(), but when I wrap it with function showMsg(

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 16:18

    1. Never use global.
      Pass $connection into your function as an argument.

    2. Logic and representation should be separated.
      Read about MVC: here or here.

    3. Global variables are evil, never use it. If someone suggests it - ignore all their answers.

提交回复
热议问题