簡體   English   中英

建立從Eclipse到PHP數據庫文件的連接

[英]Building a connection from Eclipse to a PHP database file

這是我的代碼,用於建立從Eclipse到包含我的數據庫連接的PHP文件的連接,但是它將空字符串存儲到數據庫。 誰能指出我一路上可能犯的錯誤?

 add.setOnClickListener(new View.OnClickListener() {


           public void onClick(View arg0) {
           Intent add = new Intent(addUser.this, FavUser.class);
           startActivity(add);

           InputStream is = null;


           EditText txtSearch = (EditText) findViewById(R.id.txtSearch);
           String strSearch = txtSearch.getText().toString();

           List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
           nameValuePairs.add(new BasicNameValuePair(strSearch, strSearch));

           try {

               // Add your data

               HttpClient httpclient = new DefaultHttpClient();
               HttpPost httppost = new HttpPost("http://10.0.2.2/connecttodb.php");

               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

               // Execute HTTP Post Request
               HttpResponse response = httpclient.execute(httppost);
               HttpEntity entity = response.getEntity();
              is = entity.getContent();

           } catch (IOException e) {
              Log.e("Log_tag", "error in http connection" +e.toString());
           }
           // convert reposonse to string

代碼本身看起來不錯,但是如果提供了任何錯誤消息,那就更好了。 無論如何,我建議您檢查您的IP地址。 看起來像路由器的IP,可尋址到服務器。 去谷歌並輸入“我的IP地址是什么”,然后用您正在使用的地址替換它; 如果不同。 同樣不要忘記更改代碼后將端口從路由器轉發到服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM