How do you insert a PHP constant into a SQL query?

前端 未结 4 2266
野性不改
野性不改 2020-12-18 05:34

I have a PHP file with my database configuration settings defined as constants, for example:



        
4条回答
  •  温柔的废话
    2020-12-18 05:56

    I've found two ways.

    1.-

    define("VALUE1", "someValue");
    $query = "SELECT * FROM TABLE WHERE `Column` /*=" . VALUE1 . "*/";
    

    2.-

    define("VALUE1", "someValue");
    define("VALUE2", "otherValue");
    $query = "INSERT INTO TABLE (`Column1`, `Column2`) VALUES (" . VALUE1 . ", " . VALUE2 . ")";
    

    The backticks (``) I use because I'm using phpmyadmin, you might not need them.

提交回复
热议问题