Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:50:34+00:00 2026-06-12T10:50:34+00:00

Sometime I have to use include_once and include it depend how the page are

  • 0

Sometime I have to use include_once and include it depend how the page are accessed. For example:

sales.php

include("class/pdoDatabase.php");
include("class/ClassExample.php");

$obj = new ClassExample();
$obj->getNewItem(1);

ClassExample.php

include_once("class/pdoDatabase.php");

class ClassExample {
  public function  getNewItem($id) { .. }
   public function addNew($id) { .. }
}

// Accessing this file directly via Ajax request 
if (isset($_POST['AddNew'])) {
   $obj = new ClassExample ();
   $obj->addNew($_POST['id']);
 }
}

If you access to sales.php which will then load include("class/ClassExample.php");, however I have to use include_once in the ClassExample.php because pdoDatabase.php might be already loaded in sales.php.
If you access the file directly to ClassExample.php with POST query, it mean it will have to load the file and create an object.

Problem:
Problem is when you access to ClassExample.php directly – it could not find class/pdoDatabase.php . It work fine when sales.php load class/pdoDatabase.php file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:50:36+00:00Added an answer on June 12, 2026 at 10:50 am

    This is not a problem with include_once and include difference. This is a problem with relative paths. Include always uses paths relative to called php file. You have this file structure:

    sales.php
    [class]
     - pdoDatabase.php
     - ClassExample.php
    

    when you call sales.php everything is ok, but when you call ClassExample.php it’s trying to find class/class/pdoDatabase.php which don’t exist.

    Change include line in your ClassExample.php

    include_once(dirname(__FILE__)."/pdoDatabase.php");
    

    and use the same pattern everywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning php for sometime now. Besides reading books and doing tutorials
I have an intranet page that uses #include to include other files such as
When building dynamic websites I use a php include to make my connections to
I have the following options Use the 'Include Client Statistics' option in SSMS .
I have noticed that sometimes people have to use multiple versions of jQuery in
I have a WCF based service that I use to expose AJAX functionality. Sometimes
I have a couple of jobs that use a shared resource (database), which sometimes
When printing a report, the user sometime have the following error: CrystalDecisions.CrystalReports.Engine.LogOnException: Error in
Does Javascript or jQuery have sometime like the in statement in Python? a in
Sometime in VB.net i have something like: For Each El in Collection Write(El) Next

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.