此代码给出了错误。
<?php
class DbOperation
{
private $con;
function __construct()
{
require_once dirname(__FILE__) . '/DbConnect.php';
$db = new DbConnect();
$this->con = $db->connect();
}
function UyingaKirish($data){
function Tekshir($ki1){
$stmt2=$this->con->prepare("SELECT HowManyPlayers FROM groups WHERE NumberOfGroup=?"); //error is here
$stmt2->bind_param("i",$ki1);
$stmt2->execute();
$stmt2->store_result();
return $ki1;
}
$u=Tekshir(5);
}
但是当我这样使用时,效果很好
class DbOperation
{
private $con;
function __construct()
{
require_once dirname(__FILE__) . '/DbConnect.php';
$db = new DbConnect();
$this->con = $db->connect();
}
function UyingaKirish($data){
$u=5;
$stmt2=$this->con->prepare("SELECT HowManyPlayers FROM groups WHERE NumberOfGroup=?");
$stmt2->bind_param("i",$u);
$stmt2->execute();
$stmt2->store_result();
}
所以整个错误是
致命错误,当不在对象上下文中时使用$ this
如何在函数内部使用它?