Jump to content

Search the Community

Showing results for tags 'variable scope'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. I'm getting the following errors when I run `cat /var/log/apache/error.log` -> PHP Notice: Undefined variable: db_connection in /var/www/html/popreport/includes/inmate.php on line 18 -> PHP Fatal error: Call to a member function query() on a non-object in /var/www/html/popreport/includes/inmate.php on line 18 When I try this in my browser I start with test.php test.php <?php require_once("./database.php"); require_once("./inmate.php"); // foreach($query as $row) // { // print_r($row) . "<br />"; // } $inmate = array(); $inmate = new Inmate($inmate); foreach($inmate as $row) { print $row->firstl_name . "<br />"; } ?> database.php <?php include("./constants.php"); try { $db_connection = new PDO("mysql:host=$host;dbname=$db_name", $db_user, $password); $db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br />"; die(); } ?> inmate.php <?php require_once("./database.php"); class Inmate { private $first_name = ''; private $last_name = ''; private $full_name = ''; private $race = ''; private $number = 0; private $facility = ''; private $type_of_transit = ''; public function __construct($inmate) { $sql = "SELECT * FROM inmate_board"; $query = $db_connection->query($sql); $result = $query->fetch(PDO::FETCH_ASSOC); foreach($result as $row) { $this->$first_name = $result['first_name']; } } public function get_property($property) { return $this->$property; } } ?> In inmate.php I also tried to change the line `$query = $db_connection->query($sql);` to `$query = global $db_connection->query($sql);` but I didn't have any luck here either. Any ideas?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.