0

I'm fairly new to PHP and I'm trying to integrate it into my website. I have followed one tutorial and it uses a secured pdo statemetns, and this is my first time facing them. So I integrated paypal and the transcations goes well, I'm using sandbox for testing purposes. Now as I understand this code works with the IPN, so whenever transcation is made the informaton is being send to the page that checks if the payment is success and then store the informations in datebase.

I have activated IPN from my business sandbox account and now when I try to make a payment it all goes well, but the informations isn't being stored in my datebase. I have checked error log file and saw this:

[28-Dec-2019 04:05:36 UTC] PHP Fatal error:  Uncaught Error: Call to undefined method mysqli_stmt::get_result() in /home/fm4rkhoed1b3/public_html/cutesalons.com/public/locals/include/paypal/promote/DBController.php:32
Stack trace:
#0 /home/fm4rkhoed1b3/public_html/cutesalons.com/public/locals/include/paypal/promote/notify.php(109): DBController->runQuery('SELECT * FROM p...', 's', Array)
#1 {main}
  thrown in /home/fm4rkhoed1b3/public_html/cutesalons.com/public/locals/include/paypal/promote/DBController.php on line 32

Now I have read a little and saw that this can be due that I don't have a mysqli driver installed, can you please confirm?

DBController.php

<?php

class DBController
{

    private $host = "localhost";

    private $user = "locals";

    private $password = "aleksa95";

    private $database = "locals";

    private $conn;

    function __construct()
    {
        $this->conn = $this->connectDB();
    }

    function connectDB()
    {
        $conn = mysqli_connect($this->host, $this->user, $this->password, $this->database);
        return $conn;
    }

    function runQuery($query, $param_type, $param_value_array)
    {
        $sql = $this->conn->prepare($query);
        $this->bindQueryParams($sql, $param_type, $param_value_array);
        $sql->execute();
        $result = $sql->get_result();

        if ($result->num_rows > 0) {
            while ($row = $result->fetch_assoc()) {
                $resultset[] = $row;
            }
        }

        if (! empty($resultset)) {
            return $resultset;
        }
    }

    function bindQueryParams($sql, $param_type, $param_value_array)
    {
        $param_value_reference[] = & $param_type;
        for ($i = 0; $i < count($param_value_array); $i ++) {
            $param_value_reference[] = & $param_value_array[$i];
        }
        call_user_func_array(array(
            $sql,
            'bind_param'
        ), $param_value_reference);
    }

    function insert($query, $param_type, $param_value_array)
    {
        $sql = $this->conn->prepare($query);
        $this->bindQueryParams($sql, $param_type, $param_value_array);
        $sql->execute();
    }
}
?>

And this is the code i'm using to insert the info in datebase:

// Split response headers and payload, a better way for strcmp
$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp ($res, "VERIFIED") == 0) {
    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];

    include('DBController.php');
    $db = new DBController();

    // check whether the payment_status is Completed
    $isPaymentCompleted = false;
    if($payment_status == "Completed") {
        $isPaymentCompleted = true;
    }
    // check that txn_id has not been previously processed
    $isUniqueTxnId = false; 
    $param_type="s";
    $param_value_array = array($txn_id);
    $result = $db->runQuery("SELECT * FROM payment WHERE txn_id = ?",$param_type,$param_value_array);
    if(empty($result)) {
        $isUniqueTxnId = true;
    }   
    // check that receiver_email is your PayPal email
    // check that payment_amount/payment_currency are correct
    if($isPaymentCompleted) {
        $param_type = "sssdss";
        $param_value_array = array($item_number, $item_name, $payment_status, $payment_amount, $payment_currency, $txn_id);
        $payment_id = $db->insert("INSERT INTO payment(item_number, item_name, payment_status, payment_amount, payment_currency, txn_id) VALUES(?, ?, ?, ?, ?, ?)", $param_type, $param_value_array);
        error_log(date('[Y-m-d H:i e] '). "Vdddddddddddderified IPN: $req ". PHP_EOL, 3, LOG_FILE);
    } 
    // process payment and mark item as paid.


    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE);
    }

} else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
    // Add business logic here which deals with invalid IPN messages
    if(DEBUG == true) {
        error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE);
    }
}

Can anyone please help me debug this cause I think this is caussing also my IPN to fail at sending messages. I will be much appriciated.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Freelancer Help
  • 151
  • 1
  • 3
  • 13
  • If you already know a possible cause of the error, then why are you not trying to resolve the possible cause? That's your confirmation. – Shadow Dec 28 '19 at 06:57
  • Which PHP version do you use? – Dharman Dec 28 '19 at 12:35
  • @Dharman I just upgraded it to the latest PHP 7.3 – Freelancer Help Dec 28 '19 at 14:17
  • 1
    Then something must be wrong with your PHP config, because since PHP 5.4 `mysqli_stmt::get_result` is available by default. Check in your config whether `mysqlnd` is enabled. You can use `phpinfo()` to verify that. – Dharman Dec 28 '19 at 14:18
  • @Dharman man thanks so much! Yes it was in the cpanel config settings, the mysqlnd was already enabled and I had to enable nd_mysqli. You can post this as answer and I will mark it as answer. Thanks man again a lot. – Freelancer Help Dec 28 '19 at 14:38
  • Yes man, thats right. I will add upvode to that answer. Thanks again. – Freelancer Help Dec 28 '19 at 14:41
  • Please accept the duplicate if it helped. You can find the button on the top of the page. – Dharman Dec 28 '19 at 14:42

0 Answers0