Php - using include/require_once inside function











up vote
0
down vote

favorite












I am creating a class "DBQuery" that contains all the database query functions such as insert, select, delete, ...



Everything is working fine when I create database connection inside the INSERT function. But i want separate the configuration so that i can include it in any other files and pages.



configuration.php



define("HOSTNAME", "localhost");
define("USERNAME", "root");
define("PASSWORD", "");
define("DATABASE", "edubits");

try {
$conn = new PDO("mysql:host=" . HOSTNAME . ";dbname=" . DATABASE . ";", USERNAME, PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

} catch (PDOException $e) {
echo $e;
}


class.php



/**
* Created by PhpStorm.
* User: Sunusi Mohd Inuwa
* Date: 11/18/2018
* Time: 11:02 AM
*/
class QUERY
{
function INSERT($table, $data, $conn)
{
include_once('../configuration.php');

// variable declaration
$columns = "";
$valueset = "";
$values = "";

//loop
foreach ($data as $column => $value) {
$columns = $columns . ', ' . $column;
$valueset = $valueset . ', ?';
$values = $values . ', ' . $value;
}

//trimming the first comma from the result above
$columns = ltrim($columns, ',');
$valueset = ltrim($valueset, ',');
$values = ltrim($values, ',');

//statement
$sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

//convert values to array
$values = explode(',', $values);

//query
$query = $conn->prepare($sql)->execute($values);
//$query = $conn->prepare($sql)->execute([$values]);;


}
}









share|improve this question


























    up vote
    0
    down vote

    favorite












    I am creating a class "DBQuery" that contains all the database query functions such as insert, select, delete, ...



    Everything is working fine when I create database connection inside the INSERT function. But i want separate the configuration so that i can include it in any other files and pages.



    configuration.php



    define("HOSTNAME", "localhost");
    define("USERNAME", "root");
    define("PASSWORD", "");
    define("DATABASE", "edubits");

    try {
    $conn = new PDO("mysql:host=" . HOSTNAME . ";dbname=" . DATABASE . ";", USERNAME, PASSWORD);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

    } catch (PDOException $e) {
    echo $e;
    }


    class.php



    /**
    * Created by PhpStorm.
    * User: Sunusi Mohd Inuwa
    * Date: 11/18/2018
    * Time: 11:02 AM
    */
    class QUERY
    {
    function INSERT($table, $data, $conn)
    {
    include_once('../configuration.php');

    // variable declaration
    $columns = "";
    $valueset = "";
    $values = "";

    //loop
    foreach ($data as $column => $value) {
    $columns = $columns . ', ' . $column;
    $valueset = $valueset . ', ?';
    $values = $values . ', ' . $value;
    }

    //trimming the first comma from the result above
    $columns = ltrim($columns, ',');
    $valueset = ltrim($valueset, ',');
    $values = ltrim($values, ',');

    //statement
    $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

    //convert values to array
    $values = explode(',', $values);

    //query
    $query = $conn->prepare($sql)->execute($values);
    //$query = $conn->prepare($sql)->execute([$values]);;


    }
    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am creating a class "DBQuery" that contains all the database query functions such as insert, select, delete, ...



      Everything is working fine when I create database connection inside the INSERT function. But i want separate the configuration so that i can include it in any other files and pages.



      configuration.php



      define("HOSTNAME", "localhost");
      define("USERNAME", "root");
      define("PASSWORD", "");
      define("DATABASE", "edubits");

      try {
      $conn = new PDO("mysql:host=" . HOSTNAME . ";dbname=" . DATABASE . ";", USERNAME, PASSWORD);
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

      } catch (PDOException $e) {
      echo $e;
      }


      class.php



      /**
      * Created by PhpStorm.
      * User: Sunusi Mohd Inuwa
      * Date: 11/18/2018
      * Time: 11:02 AM
      */
      class QUERY
      {
      function INSERT($table, $data, $conn)
      {
      include_once('../configuration.php');

      // variable declaration
      $columns = "";
      $valueset = "";
      $values = "";

      //loop
      foreach ($data as $column => $value) {
      $columns = $columns . ', ' . $column;
      $valueset = $valueset . ', ?';
      $values = $values . ', ' . $value;
      }

      //trimming the first comma from the result above
      $columns = ltrim($columns, ',');
      $valueset = ltrim($valueset, ',');
      $values = ltrim($values, ',');

      //statement
      $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

      //convert values to array
      $values = explode(',', $values);

      //query
      $query = $conn->prepare($sql)->execute($values);
      //$query = $conn->prepare($sql)->execute([$values]);;


      }
      }









      share|improve this question













      I am creating a class "DBQuery" that contains all the database query functions such as insert, select, delete, ...



      Everything is working fine when I create database connection inside the INSERT function. But i want separate the configuration so that i can include it in any other files and pages.



      configuration.php



      define("HOSTNAME", "localhost");
      define("USERNAME", "root");
      define("PASSWORD", "");
      define("DATABASE", "edubits");

      try {
      $conn = new PDO("mysql:host=" . HOSTNAME . ";dbname=" . DATABASE . ";", USERNAME, PASSWORD);
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

      } catch (PDOException $e) {
      echo $e;
      }


      class.php



      /**
      * Created by PhpStorm.
      * User: Sunusi Mohd Inuwa
      * Date: 11/18/2018
      * Time: 11:02 AM
      */
      class QUERY
      {
      function INSERT($table, $data, $conn)
      {
      include_once('../configuration.php');

      // variable declaration
      $columns = "";
      $valueset = "";
      $values = "";

      //loop
      foreach ($data as $column => $value) {
      $columns = $columns . ', ' . $column;
      $valueset = $valueset . ', ?';
      $values = $values . ', ' . $value;
      }

      //trimming the first comma from the result above
      $columns = ltrim($columns, ',');
      $valueset = ltrim($valueset, ',');
      $values = ltrim($values, ',');

      //statement
      $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

      //convert values to array
      $values = explode(',', $values);

      //query
      $query = $conn->prepare($sql)->execute($values);
      //$query = $conn->prepare($sql)->execute([$values]);;


      }
      }






      php






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 14 hours ago









      Engr. S.M. Inuwa

      425




      425
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          Use include, not include_once. If you use include_once, then it won't execute the code in the file the second time you call the method.



          But it would probably be better to include the file in the class's constructor, so you only need to execute it once, rather than create a new connection every time you perform a query. Make $conn a class property instead of an ordinary variable.






          share|improve this answer




























            up vote
            0
            down vote













            The class below give the ability to get a connection object from getInstance() funtion, so you just include the Config class where you wanna communicate with database (model)



            getInstance() : is singleton, which means that you have a single instance



            class Config{

            private $HOSTNAME = "localhost";
            private $USERNAME = "root";
            private $PASSWORD = "";
            private $DATABASE = "edubits";
            private static $pdo = null;

            public static function getInstance($data = null){
            if(self::$pdo == null){
            self::PDOConnect($data = null);
            }
            return self::$pdo;
            }

            private static function PDOConnect(){
            try{
            $info = new DBInfo($data);
            self::$pdo = new PDO("mysql:host=" . $this->HOSTNAME . ";dbname=" . $this->DATABASE . ";", $this->USERNAME, $this->PASSWORD);
            self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
            } catch (PDOException $e) {
            echo new PDOCustomException($e->getMessage(), null, $e);
            }
            }

            public function close(){
            return null;
            }
            }


            Here i've choice to use config directly from your INSERT function to get connection object, or get connexion object in constructor one time and use it many time in QUERY class



            So connection instance is stored on $cn



            include_once('../configuration.php');

            class QUERY
            {
            private $cn = null;
            private $DBAction = null;

            public function __construct(){
            try {
            $cn = new DBAction();
            $this->cn = $cn::getInstance();
            } catch (PDOException $ex) {
            throw new PDOCustomException($ex->getMessage(), null, $ex);
            } catch (Exception $ex) {
            throw new CustomException($ex->getMessage(), null, $ex);
            }
            }

            public function INSERT($table, $data, $conn) {
            $config = new Config();

            // variable declaration
            $columns = "";
            $valueset = "";
            $values = "";

            //loop
            foreach ($data as $column => $value) {
            $columns = $columns . ', ' . $column;
            $valueset = $valueset . ', ?';
            $values = $values . ', ' . $value;
            }

            //trimming the first comma from the result above
            $columns = ltrim($columns, ',');
            $valueset = ltrim($valueset, ',');
            $values = ltrim($values, ',');

            //statement
            $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

            //convert values to array
            $values = explode(',', $values);

            //query
            $query = $this->cn->prepare($sql)->execute($values);

            }
            }





            share|improve this answer























            • This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
              – Engr. S.M. Inuwa
              12 hours ago










            • Updated to be clear
              – M. Hanafi
              12 hours ago











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371481%2fphp-using-include-require-once-inside-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            Use include, not include_once. If you use include_once, then it won't execute the code in the file the second time you call the method.



            But it would probably be better to include the file in the class's constructor, so you only need to execute it once, rather than create a new connection every time you perform a query. Make $conn a class property instead of an ordinary variable.






            share|improve this answer

























              up vote
              3
              down vote













              Use include, not include_once. If you use include_once, then it won't execute the code in the file the second time you call the method.



              But it would probably be better to include the file in the class's constructor, so you only need to execute it once, rather than create a new connection every time you perform a query. Make $conn a class property instead of an ordinary variable.






              share|improve this answer























                up vote
                3
                down vote










                up vote
                3
                down vote









                Use include, not include_once. If you use include_once, then it won't execute the code in the file the second time you call the method.



                But it would probably be better to include the file in the class's constructor, so you only need to execute it once, rather than create a new connection every time you perform a query. Make $conn a class property instead of an ordinary variable.






                share|improve this answer












                Use include, not include_once. If you use include_once, then it won't execute the code in the file the second time you call the method.



                But it would probably be better to include the file in the class's constructor, so you only need to execute it once, rather than create a new connection every time you perform a query. Make $conn a class property instead of an ordinary variable.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 14 hours ago









                Barmar

                412k34237339




                412k34237339
























                    up vote
                    0
                    down vote













                    The class below give the ability to get a connection object from getInstance() funtion, so you just include the Config class where you wanna communicate with database (model)



                    getInstance() : is singleton, which means that you have a single instance



                    class Config{

                    private $HOSTNAME = "localhost";
                    private $USERNAME = "root";
                    private $PASSWORD = "";
                    private $DATABASE = "edubits";
                    private static $pdo = null;

                    public static function getInstance($data = null){
                    if(self::$pdo == null){
                    self::PDOConnect($data = null);
                    }
                    return self::$pdo;
                    }

                    private static function PDOConnect(){
                    try{
                    $info = new DBInfo($data);
                    self::$pdo = new PDO("mysql:host=" . $this->HOSTNAME . ";dbname=" . $this->DATABASE . ";", $this->USERNAME, $this->PASSWORD);
                    self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                    } catch (PDOException $e) {
                    echo new PDOCustomException($e->getMessage(), null, $e);
                    }
                    }

                    public function close(){
                    return null;
                    }
                    }


                    Here i've choice to use config directly from your INSERT function to get connection object, or get connexion object in constructor one time and use it many time in QUERY class



                    So connection instance is stored on $cn



                    include_once('../configuration.php');

                    class QUERY
                    {
                    private $cn = null;
                    private $DBAction = null;

                    public function __construct(){
                    try {
                    $cn = new DBAction();
                    $this->cn = $cn::getInstance();
                    } catch (PDOException $ex) {
                    throw new PDOCustomException($ex->getMessage(), null, $ex);
                    } catch (Exception $ex) {
                    throw new CustomException($ex->getMessage(), null, $ex);
                    }
                    }

                    public function INSERT($table, $data, $conn) {
                    $config = new Config();

                    // variable declaration
                    $columns = "";
                    $valueset = "";
                    $values = "";

                    //loop
                    foreach ($data as $column => $value) {
                    $columns = $columns . ', ' . $column;
                    $valueset = $valueset . ', ?';
                    $values = $values . ', ' . $value;
                    }

                    //trimming the first comma from the result above
                    $columns = ltrim($columns, ',');
                    $valueset = ltrim($valueset, ',');
                    $values = ltrim($values, ',');

                    //statement
                    $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

                    //convert values to array
                    $values = explode(',', $values);

                    //query
                    $query = $this->cn->prepare($sql)->execute($values);

                    }
                    }





                    share|improve this answer























                    • This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
                      – Engr. S.M. Inuwa
                      12 hours ago










                    • Updated to be clear
                      – M. Hanafi
                      12 hours ago















                    up vote
                    0
                    down vote













                    The class below give the ability to get a connection object from getInstance() funtion, so you just include the Config class where you wanna communicate with database (model)



                    getInstance() : is singleton, which means that you have a single instance



                    class Config{

                    private $HOSTNAME = "localhost";
                    private $USERNAME = "root";
                    private $PASSWORD = "";
                    private $DATABASE = "edubits";
                    private static $pdo = null;

                    public static function getInstance($data = null){
                    if(self::$pdo == null){
                    self::PDOConnect($data = null);
                    }
                    return self::$pdo;
                    }

                    private static function PDOConnect(){
                    try{
                    $info = new DBInfo($data);
                    self::$pdo = new PDO("mysql:host=" . $this->HOSTNAME . ";dbname=" . $this->DATABASE . ";", $this->USERNAME, $this->PASSWORD);
                    self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                    } catch (PDOException $e) {
                    echo new PDOCustomException($e->getMessage(), null, $e);
                    }
                    }

                    public function close(){
                    return null;
                    }
                    }


                    Here i've choice to use config directly from your INSERT function to get connection object, or get connexion object in constructor one time and use it many time in QUERY class



                    So connection instance is stored on $cn



                    include_once('../configuration.php');

                    class QUERY
                    {
                    private $cn = null;
                    private $DBAction = null;

                    public function __construct(){
                    try {
                    $cn = new DBAction();
                    $this->cn = $cn::getInstance();
                    } catch (PDOException $ex) {
                    throw new PDOCustomException($ex->getMessage(), null, $ex);
                    } catch (Exception $ex) {
                    throw new CustomException($ex->getMessage(), null, $ex);
                    }
                    }

                    public function INSERT($table, $data, $conn) {
                    $config = new Config();

                    // variable declaration
                    $columns = "";
                    $valueset = "";
                    $values = "";

                    //loop
                    foreach ($data as $column => $value) {
                    $columns = $columns . ', ' . $column;
                    $valueset = $valueset . ', ?';
                    $values = $values . ', ' . $value;
                    }

                    //trimming the first comma from the result above
                    $columns = ltrim($columns, ',');
                    $valueset = ltrim($valueset, ',');
                    $values = ltrim($values, ',');

                    //statement
                    $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

                    //convert values to array
                    $values = explode(',', $values);

                    //query
                    $query = $this->cn->prepare($sql)->execute($values);

                    }
                    }





                    share|improve this answer























                    • This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
                      – Engr. S.M. Inuwa
                      12 hours ago










                    • Updated to be clear
                      – M. Hanafi
                      12 hours ago













                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    The class below give the ability to get a connection object from getInstance() funtion, so you just include the Config class where you wanna communicate with database (model)



                    getInstance() : is singleton, which means that you have a single instance



                    class Config{

                    private $HOSTNAME = "localhost";
                    private $USERNAME = "root";
                    private $PASSWORD = "";
                    private $DATABASE = "edubits";
                    private static $pdo = null;

                    public static function getInstance($data = null){
                    if(self::$pdo == null){
                    self::PDOConnect($data = null);
                    }
                    return self::$pdo;
                    }

                    private static function PDOConnect(){
                    try{
                    $info = new DBInfo($data);
                    self::$pdo = new PDO("mysql:host=" . $this->HOSTNAME . ";dbname=" . $this->DATABASE . ";", $this->USERNAME, $this->PASSWORD);
                    self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                    } catch (PDOException $e) {
                    echo new PDOCustomException($e->getMessage(), null, $e);
                    }
                    }

                    public function close(){
                    return null;
                    }
                    }


                    Here i've choice to use config directly from your INSERT function to get connection object, or get connexion object in constructor one time and use it many time in QUERY class



                    So connection instance is stored on $cn



                    include_once('../configuration.php');

                    class QUERY
                    {
                    private $cn = null;
                    private $DBAction = null;

                    public function __construct(){
                    try {
                    $cn = new DBAction();
                    $this->cn = $cn::getInstance();
                    } catch (PDOException $ex) {
                    throw new PDOCustomException($ex->getMessage(), null, $ex);
                    } catch (Exception $ex) {
                    throw new CustomException($ex->getMessage(), null, $ex);
                    }
                    }

                    public function INSERT($table, $data, $conn) {
                    $config = new Config();

                    // variable declaration
                    $columns = "";
                    $valueset = "";
                    $values = "";

                    //loop
                    foreach ($data as $column => $value) {
                    $columns = $columns . ', ' . $column;
                    $valueset = $valueset . ', ?';
                    $values = $values . ', ' . $value;
                    }

                    //trimming the first comma from the result above
                    $columns = ltrim($columns, ',');
                    $valueset = ltrim($valueset, ',');
                    $values = ltrim($values, ',');

                    //statement
                    $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

                    //convert values to array
                    $values = explode(',', $values);

                    //query
                    $query = $this->cn->prepare($sql)->execute($values);

                    }
                    }





                    share|improve this answer














                    The class below give the ability to get a connection object from getInstance() funtion, so you just include the Config class where you wanna communicate with database (model)



                    getInstance() : is singleton, which means that you have a single instance



                    class Config{

                    private $HOSTNAME = "localhost";
                    private $USERNAME = "root";
                    private $PASSWORD = "";
                    private $DATABASE = "edubits";
                    private static $pdo = null;

                    public static function getInstance($data = null){
                    if(self::$pdo == null){
                    self::PDOConnect($data = null);
                    }
                    return self::$pdo;
                    }

                    private static function PDOConnect(){
                    try{
                    $info = new DBInfo($data);
                    self::$pdo = new PDO("mysql:host=" . $this->HOSTNAME . ";dbname=" . $this->DATABASE . ";", $this->USERNAME, $this->PASSWORD);
                    self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
                    } catch (PDOException $e) {
                    echo new PDOCustomException($e->getMessage(), null, $e);
                    }
                    }

                    public function close(){
                    return null;
                    }
                    }


                    Here i've choice to use config directly from your INSERT function to get connection object, or get connexion object in constructor one time and use it many time in QUERY class



                    So connection instance is stored on $cn



                    include_once('../configuration.php');

                    class QUERY
                    {
                    private $cn = null;
                    private $DBAction = null;

                    public function __construct(){
                    try {
                    $cn = new DBAction();
                    $this->cn = $cn::getInstance();
                    } catch (PDOException $ex) {
                    throw new PDOCustomException($ex->getMessage(), null, $ex);
                    } catch (Exception $ex) {
                    throw new CustomException($ex->getMessage(), null, $ex);
                    }
                    }

                    public function INSERT($table, $data, $conn) {
                    $config = new Config();

                    // variable declaration
                    $columns = "";
                    $valueset = "";
                    $values = "";

                    //loop
                    foreach ($data as $column => $value) {
                    $columns = $columns . ', ' . $column;
                    $valueset = $valueset . ', ?';
                    $values = $values . ', ' . $value;
                    }

                    //trimming the first comma from the result above
                    $columns = ltrim($columns, ',');
                    $valueset = ltrim($valueset, ',');
                    $values = ltrim($values, ',');

                    //statement
                    $sql = "INSERT INTO " . $table . "(" . $columns . ") VALUES(" . $valueset . ")";

                    //convert values to array
                    $values = explode(',', $values);

                    //query
                    $query = $this->cn->prepare($sql)->execute($values);

                    }
                    }






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 12 hours ago

























                    answered 13 hours ago









                    M. Hanafi

                    439




                    439












                    • This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
                      – Engr. S.M. Inuwa
                      12 hours ago










                    • Updated to be clear
                      – M. Hanafi
                      12 hours ago


















                    • This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
                      – Engr. S.M. Inuwa
                      12 hours ago










                    • Updated to be clear
                      – M. Hanafi
                      12 hours ago
















                    This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
                    – Engr. S.M. Inuwa
                    12 hours ago




                    This seems logical and a bit complicated to my understanding. More explanation is highly appreciated.
                    – Engr. S.M. Inuwa
                    12 hours ago












                    Updated to be clear
                    – M. Hanafi
                    12 hours ago




                    Updated to be clear
                    – M. Hanafi
                    12 hours ago


















                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371481%2fphp-using-include-require-once-inside-function%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    SQL update select statement

                    'app-layout' is not a known element: how to share Component with different Modules