include, include_once, require or require_once?

前端 未结 8 1180
误落风尘
误落风尘 2020-11-27 17:21

I have PHP file where I have defined the server access variables as well as the mysql_connect and mysql_select_db, as this functions are regularly

8条回答
  •  Happy的楠姐
    2020-11-27 17:36

    "."Included"."
    "; include_once('db.php'); echo "
    "."Again included"."
    "; ?>

    In the Above Code, I have included a file using include statement at the top, the file get included.

    Next I have used include_once to include the same file, But as the file was already included above, it will not be included again here.

    Output:

    Connected             -----This is from db.php File
    Included
    
    Again included
    

    ==========================

    include_once('db.php');
    
    echo "
    "."Again included"."
    "; include('db.php'); echo "
    "."Included"."
    "; ?>

    In the above code, I have used include_once at the top, so the file is included But in the next code I have again used include_once for the same file, then again the file will get included and the output will be

    Output:

    Again included
    Connected
    Included
    Connected
    

提交回复
热议问题