Jump to content

legacy800

Members
  • Posts

    26
  • Joined

  • Last visited

Everything posted by legacy800

  1. Ok it's pretty clear to me now, if you want to use properties in multiple classes you need to declare them outside the methods. Thanks for the help, I really appreciate it!
  2. Can you please clarify on how to do this in this example. Because just referring to the php.net manual is not helping me one bit.
  3. Hello, Recently i've picked up php and I'm stuck. I'm following some net.tutsplus tutorials by Jeffrey Way on PDO database acces and I'm trying to incorperate this into a class without luck. <?phpclass Database {function __construct(){ try { $conn = new PDO('mysql:host=localhost;dbname=blog', 'root', ''); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $error) { echo 'ERROR: ' . $error->getMessage(); }}function get($conn) { $stmt = $conn->prepare('SELECT * FROM users'); $stmt->execute(); while($row = $stmt->fetch()) { print_r($row); }}}$database = new Database; Where I'm getting stuck is passing the $conn attribute from the construct method to my get method. After including this class into my index file I'm trying to call my class get method by: <?php $database->get(); ?> But I have no idea what to pass as argument. the $conn property holds the Data Object but I can't simply use $conn as argument because I will get an 'undefined variable' message wich is logically since it's in the constructor. What can I do to make this work, how can i pass the $conn variable from my constructor to my get method?
×
×
  • Create New...