Friday 19 May 2017

How to accomplish the below PHP script in node.js.

Here I am trying to bind the parameters of the insertOrganisation function. that is var=organisation, and var = parentId, to the values which am inserting into my sql database using the query below (insertQuery).

function insertOrganisation($organisation, $parentId) {

    // validate incoming parameters
    // I assume you are using PDO and have established a successful database connection
    $dbh = new PDO(......);
    $insertQuery = "INSERT INTO organization (org_name, parent_id) VALUES (:name, :parent_id) ON DUPLICATE KEY UPDATE parent_id = VALUES(parent_id)";
    $stmt = $dbh->prepare($insertQuery);
    $stmt->bindValue(':parent_id', $parentId, PDO::PARAM_INT);
    $stmt->bindValue(':name', $organisation->org_name, PDO::PARAM_STR);
    $stmt->execute();

Question is: How can i bind the parameters of the insertOrganisation() function, that is: var = organisation, var = parentId to the values inserted by the query(insertQuery), that is (org_name, parent_id) in Node.js. Thanks in Advance



via giresse

No comments:

Post a Comment