4
For example I have a class called user:
class User
{
    public $nome;
    private $email;
    protected $senha;
    public function __construct(){
    }
    public function insert($email, $senha){
        require_once "conexao.php";
        $pdo = conectar();
        $insertSQL = $pdo->prepare('INSERT INTO tbl (valores) VALUES (?)');
        $insertSQL->bindValue(1, $this->lalala(), PDO::PARAM_STR);
        $insertSQL->execute();
    }
and also see that I need to do the require():
require_once "conexao.php";
$pdo = connect();
But I have to do these two lines every time for every method in the class. There is no way to create a single time and be available in all class scope, like attributes?
I’ve tried as an attribute and it didn’t work. With the constructor it wasn’t either (maybe I did wrong).
Create a connection property in the class, it receives the connection by the constructor, whenever the object needs it will already be created.
– rray
Like a public $Pdo @rray? And in the require constructor and then $Pdo = connect()?
– System.Linq
How so help me @rray
– System.Linq
Your name is almost the same as my @LINQ
– System.Linq
I found it quite different, @System.Linq
– Jéf Bueno