Как использовать Android Connect PHP создать базу данных MySQL и таблицу?

Я хочу подключить php, чем создать таблицу с помощью Android

но у меня есть вопрос, я не знаю, как решить

1. это мой класс Android

public class MainActivity extends Activity {
public class MainActivity extends Activity {
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t = (TextView)findViewById(R.id.Textview1);
GetServerMessage message = new GetServerMessage();
String msg = message.stringQuery("http://114.33.140.95/CreateTable.php");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

}
}

2. андроид тоже

public class GetServerMessage {
public String stringQuery(String url){
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
HttpResponse response = httpclient.execute(method);
HttpEntity entity = response.getEntity();
if(entity != null){
return EntityUtils.toString(entity);
}
else{
return "Network connected success.";
}
}
catch(Exception e){
return "Network have problem";
}
}
}

Android подключить php создать таблицу

<?php
$con=mysqli_connect("http://114.33.140.95/CreateTable.php","root","","androidhive");
$sql="CREATE TABLE table1(Username CHAR(30),Password CHAR(30),Role CHAR(30))";
if (mysqli_query($con,$sql))
{
echo "Table have been created successfully";
} else {
echo "This msg is = Table created fail ";
}
?>

но, после подключения Android, php, я получу сообщение

Warning: mysqli_connect(): in C:\xampp\htdocs\CreateTable.php on line 2

Warning: mysqli_connect(): in C:\xampp\htdocs\CreateTable.php on line 2

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\CreateTable.php on line 4
This msg is = Table created fail

0

Решение

+ Изменить http://114.33.140.95/CreateTable.php на локальный хост в mysqli_connect ().

mysqli_connect("localhost","my_user","my_password","my_db");

Пожалуйста, обратитесь по этой ссылке.
http://php.net/manual/en/function.mysqli-connect.php

1

Другие решения

Других решений пока нет …