Home » Php » Simple PHP passing in a parameter and getting a result. – Does not work

Simple PHP passing in a parameter and getting a result. – Does not work

Posted by: admin February 25, 2020 Leave a comment

Questions:

Testing this what I think is a basic PHP page.

I pass a parameter in and get a result and hand it back…

BUT it does not seem to work. I am missing something basic?

I am trying to call this from a swift program but it is not working.

<?php
$servername = "123.456.789.000";
$username   = "password";
$password   = "test";
$dbname     = "database1";

    $conn = new PDO(
            "mysql:host=$servername;dbname=$dbname", $username, $password);

    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected to DB successfully";

    $arr = [];
    $mysqli = new mysqli($servername, $username, $password, $dbname);

    $stmt = $mysqli->prepare(
        "SELECT Event_text from Event WHERE EventId = '1' ");

   // $stmt->bind_param("a", $_POST['EventId']);
    $stmt->execute();

    echo "</br> Made it here";

    $stmt -> bind_result($Event_text);

    echo "</br> Made it here 1";

    $stmt -> fetch();

    while ($stmt->fetch()) {
        echo $stmt;
        echo "</br> Made it here 2";
    }

   echo "</br> Made it here 3";

   $stmt -> close();
   $mysqli -> close();

} catch (PDOException $e) {
    $conn = null;
    echo $e->getMessage();
    exit("Connection failed: " . $e->getMessage());
}

?>

The output is:

Connected to DB successfully

Made it here

Made it here 1

Made it here 3

How to&Answers: