formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Running a stored procedure from FT #677

Open matsed opened 4 years ago

matsed commented 4 years ago

Hi Ben,

here's another weird thing I'm trying to do. I want to run stored procedure on the underlying database using a link or button on a FT page. The aim is to change some existing submission data through this action. I've created a new php page and linked to it from a FT page (page module). I get this error: Error occurred:SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost ' (95)

It's seems the call for the hostname returns localhost and the procedure call doesn't get through. Here's my code, the requires and parameter calls are from existing FT pages and they are OK. The echoes show the right info but hostname is localhost which doesn't seem to get through in the PDO.

' <?php

require("../../global/session_start.php"); require_once ("../../global/config.php");

ft_check_permission("client");

$request = array_merge($_POST, $_GET); $account_id = $_SESSION["ft"]["account"]["account_id"];

/ echo $account_id; echo $g_db_hostname ; echo $g_db_name; echo $g_db_username; echo $g_db_password; /

try {

    $pdo = new PDO("mysql:host=$g_db_hostname ;dbname=$g_db_name ", $g_db_username , $g_db_password );

    // calling stored procedure command
    $sql = 'CALL test_proc2';

    // prepare for execution of the stored procedure
    $stmt = $pdo->prepare($sql);

    // pass value to the command
    $stmt->bindParam(':p_accountid', $account_id, PDO::PARAM_INT);

    // execute the stored procedure
    $stmt->execute();

    $stmt->closeCursor();

} catch (PDOException $e) { die("Error occurred:" . $e->getMessage()); } return null;

Help MUCH appreciated!

Thanks, M