简体   繁体   中英

PHP require_once error

I am using CODA, MAMP and am working out of my HTdocs folder all locally. I am learning PHP and MVC structure and an coming across the following error when using require_once. I have read many of the other posts on this topic and no solution has worked.

The error I am receiving is:

Warning: require_once(UserModel.php): failed to open stream:
No such file or directory in - on line 13 Fatal error: require_once():
Failed opening required 'UserModel.php' (include_path='.:') in - on line 13

My file structure is:

database
----bdfdatabase.sql
index.php
UserModel.php

My code is as follows

<?php   
    require_once('UserModel.php');

    $dsn = "mysql:host=127.0.0.1;port=8889;dbname=bdfdatabase";
    $db_user= "root";
    $db_pass= "root";
    $model = new UserModel($dsn, $db_user, $db_pass);
    $rows = $model->displayUsers();

        foreach($rows as $row){
            echo "<h3><a href='details.php'>";
            echo "${row['user_name']}";
            echo "</a></h3>";
        }

?>

Any suggestions would be much appreciated.

Most probably, The problem is once again the Path .

  1. Make sure UserModel.php lies in the same folder as the one from which you are running the above code.

  2. Make sure you have access to read that file. The file must be readable by owners, group, and others, to be included as such. Change the mode of the file to 0774 to confirm this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM