我正在尝试将我的php脚本与我的数据库连接到在线服务器中。我正在尝试使用require_once函数,但是我收到fatal_error时出现以下错误消息。
Warning: require_once(/home/username/public_html/droidDBtest/android_login_api/include/DB_Functions.php): failed to open stream: No such file or directory in /home/username/public_html/droidDBtest/android_login_api/register.php on line 3
Fatal error: require_once(): Failed opening required '/home/username/public_html/droidDBtest/android_login_api/include/DB_Functions.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/public_html/droidDBtest/android_login_api/register.php on line 3
我试图遵循stackoverflow的第一个结果并添加了Document Root,但是,它仍然无法正常工作。 这是我收到错误的代码:
require_once ($_SERVER['DOCUMENT_ROOT'].'/android_login_api/include/DB_Functions.php');
以下是我服务器中的文件夹结构
public_html/
-- droidDBtest
-- android_login_api
-- include
config.php
DB_Connect.php
DB_Functions.php
register.php
提前致谢。
答案 0 :(得分:0)
正如您所看到的,如果您将错误消息与文件夹结构进行比较,那么您将错过android_login_api
文件夹。
这应该有效:
require_once ($_SERVER['DOCUMENT_ROOT'].'/android_login_api/include/DB_Functions.php');
此外,您似乎是从register.php
文件夹中的android_login_api
执行此操作。所以你可以做一个相对路径:
require_once 'include/DB_Functions.php';
答案 1 :(得分:0)
查看你的目录结构,假设socument root是public_html,你应该这样做:
public class StuffManagerInputDialogFragment extends DialogFragment {
EditText nameInputField;
EditText tagInputField;
DBHandler dbHandler;
StuffManagerFragment f = new StuffManagerFragment();
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
final View v_iew = inflater.inflate(R.layout.fragment_inputdialog, null);
nameInputField = (EditText) v_iew.findViewById(R.id.inputdialogname);
tagInputField = (EditText) v_iew.findViewById(R.id.inputdialogtag);
dbHandler = new DBHandler(getActivity(), null, null, 1);
final MainActivity ma = (MainActivity) getActivity();
final AlertDialog.Builder newLinkDialog = new AlertDialog.Builder(getActivity());
newLinkDialog.setView(v_iew)
.setTitle("New Link")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String nameInputFieldText = nameInputField.getText().toString();
String tagInputFieldText = tagInputField.getText().toString();
ArrayList<String> nameArray = dbHandler.nameArrayMethod();
ArrayList<String> tagArray = dbHandler.tagArrayMethod();
NavigationView navigationView = (NavigationView) getActivity().findViewById(R.id.nav_view);
Menu menu = navigationView.getMenu();
if (nameArray.contains(nameInputFieldText) || tagArray.contains(tagInputFieldText)) {
if (nameArray.contains(nameInputFieldText) && tagArray.contains(tagInputFieldText)) {
AlertDialog.Builder errorBoth = new AlertDialog.Builder(getActivity())
.setTitle("Error")
.setMessage("The name and tag you entered are already in use.")
.setIcon(R.drawable.ic_error_black)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Return to previous dialog here
}
});
errorBoth.show();
}
} else {
dbHandler.addLink(nameInputFieldText, tagInputFieldText);
nameArray = dbHandler.nameArrayMethod();
int nameArraySize = (nameArray.size() - 1);
MenuItem item = menu.add(R.id.group1, nameArraySize, 1, nameArray.get(nameArraySize));
Toast.makeText(getContext(), "'" + nameInputFieldText + " - " + tagInputFieldText + "' link saved.", Toast.LENGTH_SHORT).show();
ma.addSMVFFragments();
f.hideDeleteAllButton = false;
getActivity().invalidateOptionsMenu();
}
}
})
.setNegativeButton("Cancel", null);
return newLinkDialog.create();
}
}