0
Hello I have the following php code
function updateRecord($email, $score){
$sql = "UPDATE record set record = $score where email = '$email' ";
$banco-> initBD()->exec($sql); //O Log indica o erro nessa linha
if($banco->rowCount()>0){
$obj = array("resposta"=>1);
}else{
$obj = array("resposta"=>2);
}
$array[] = $obj;
// json_encode($array);
echo stripslashes( json_encode($array));
}
function initBD(){
//servidor online
$opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND=> 'SET NAMES UTF8');
return (new \PDO ('mysql:host=localhost;port=80;dbname=yyyyyy; charset=utf8', 'login', 'senha', $opcoes));
}
I don’t know if that’s enough to answer the question, but I’m waiting for the feedback.
It is not enough, where is being instantiated the object "bank" and initdb is a method of that object? apparently it is a function only
– mau humor
tries to trade "$bank-> initBD()->exec($sql);" for only "initBD()->exec($sql);"
– mau humor
Who executes is a library in Volley. However, Log indicates that the json was sent, however the error happens only in this part. I’ll try the dirt.
– wagnermps
" Call to a Member Function initBD() on a non-object", that is $bank is not an object, but, still you are trying to access a method from it. So I asked him where he’s being instantiated, but he’s actually not. I also noticed that in your code, there is a function with the same name as the invoked method. It was the code of this function that you tried to use on the line that gave problem?
– mau humor
yes so I only added the two functions to the question, the line indicating the method call and the Initbd method()
– wagnermps
Then it would be better to separate and specify. In the first section "Line that failed:" and "Method called:". But as I said, the method called is irrelevant. $bank is not an object. It shows the chunk where $bank is being set (Receiving an instance, or anything). I also recommend using: http://php.net/manual/en/function.gettype.php and pass $bank as parameter, and see the answer.
– mau humor