我们正在尝试使用PHP连接到我们的本地mysql数据库。我们故意遗漏了密码,但是它是正确的。但是,这不起作用,我们不断收到以下错误消息:警告:mysqli_connect()期望参数5为long,字符串为。
指的是第7行@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.menu_search_view_explore_ideas, menu);
SearchManager searchManager =
(SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setQueryHint("Search...");
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setTextColor(Color.WHITE);
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(getResources().getColor(R.color.notify_user_color));
if (searchManager != null) {
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getActivity().getComponentName()));
}
AutoCompleteTextView searchTextView = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
try {
Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
mCursorDrawableRes.setAccessible(true);
mCursorDrawableRes.set(searchTextView, R.drawable.cursor_for_search_view); //This sets the cursor resource ID to 0 or @null which will make it visible on white background
} catch (Exception e) {
}
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mAdapter.getFilter().filter(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
mAdapter.getFilter().filter(newText);
return true;
}
});
}
$conn = mysqli_connect($servername, $port, $uname, $pword, $dbname);
我们的confiq.php文件
<?php
$servername = "Mysql@127.0.0.1";
$port = "3306";
$uname = "root@localhost";
$pword = "1234";
$dbname = "database";
$conn = mysqli_connect($servername, $port, $uname, $pword, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
答案 0 :(得分:1)
构造函数
中的args顺序错误$conn = mysqli_connect($servername, $port, $uname, $pword, $dbname);
should be
$conn = mysqli_connect($servername, $uname, $pword, $dbname, $port );
但是看起来配置文件中的信息不正确 -
define('DB_HOST', 'Mysql@127.0.0.1');
我怀疑,实际上是
define('DB_HOST', '127.0.0.1');
虽然也许不是!
然后,使用配置文件中的信息,连接将是:
$conn = mysqli_connect( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, port );