• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

SQL Request takes very long, when put into a function

I do have an SQL Table looking like:

uid   price   timestamp   account

and I want to write to this table via php. I do have this code:

function test($uid,$price){
    if($price>1){
        test2($uid,$price,2);
    else($price<1){
        test2($uid,$price,1);
    }
}
function test2($uid,$price,$accountNumber){
        $time = time();
        $conn = new PDO('sqlite:sql.db');
        $stmt = $conn -> prepare("INSERT INTO table (uid,price,timestamp,account) VALUES (:uid,:price,:timestamp,:accountNumber)");
        $stmt -> bindParam(':uid', $uid);
        $stmt -> bindParam(':price', $price);
        $stmt -> bindParam(':timestamp', $time);
        $stmt -> bindParam(':accountNumber', $accountNumber);
        $stmt -> execute();
        $conn = NULL;   
}

This request takes a huge amount of time and the serveer doesn't respond to anything during that time. However. When I don't call the function and instead replace test2($uid,$price,2); with

    $time = time();
    $conn = new PDO('sqlite:sql.db');
    $stmt = $conn -> prepare("INSERT INTO table (uid,price,timestamp,account) VALUES (:uid,:price,:timestamp,2)");
    $stmt -> bindParam(':uid', $uid);
    $stmt -> bindParam(':price', $price);
    $stmt -> bindParam(':timestamp', $time);
    $stmt -> execute();
    $conn = NULL;

The code runs way faster. The request doesn't take around 1 minute, but a few ms to process. Is there anything I am doing wrong while calling the test2 function?