This may be a question that has been answered before - if so, just leave a comment below and I will delete it.
I studied classes in PHP and at the same time made the transition to PDO.
One concept that I cannot find is how to learn the equivalent of this to classes:
config.php
<?php $host = 'localhost'; $user = 'user'; $pass = 'pass'; $con = mysql_connect($host, $user, $pass) or die("MySQL Error"); mysql_select_db("account_db", $con); ?>
another.php
<?php require_once('config.php'); $selectStatement = "SELET foo FROM bar"; $selectQuery = mysql_query($selectStatement, $con); ?>
I did not quite understand how to create a configuration file / class for a PDO connection, and then use it in another class, i.e. users, as shown below:
<?php class Users { private $_userId; function setUserId($username) {
Thanks everyone :)
source share