Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将记录插入MySQL,但未显示错误_Java_Php_Mysql_Sqlite_Mysqli - Fatal编程技术网

Java 无法将记录插入MySQL,但未显示错误

Java 无法将记录插入MySQL,但未显示错误,java,php,mysql,sqlite,mysqli,Java,Php,Mysql,Sqlite,Mysqli,任务:将记录从android sqlite同步到mysql 问题:mysql/php没有在mysql中向我的表插入数据。但没有显示任何错误 DB_Connect.php: <?php class DB_Connect { // constructor function __construct(){ } // destructor function __destruct(){ } // connecting to datab

任务:将记录从android sqlite同步到mysql

问题:mysql/php没有在mysql中向我的表插入数据。但没有显示任何错误

DB_Connect.php:

<?php

class DB_Connect {

    // constructor
    function __construct(){

    }

    // destructor
    function __destruct(){

    }

    // connecting to database
    public function connect(){
        require_once 'config.php';  // defined DB_HOST,DB_USER,DB_PASSWORD here
        // connecting to mysql
        $con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD);
        // selecting database
        mysqli_select_db($con,"heart");
        // return database handler
        return $con;
    }

    // closing database connection
    public function close(){
        mysqli_close($this->connect());
    }
}

?>

DB_Operations.php:

<?php
class DB_Operations {

    private $db;
    public $last_id;
    public $error;
    public $error_conn;
    public $error_no;

    // constructor
    function __construct(){
        require 'DB_Connect.php';
        $this->db = new DB_Connect();
        $this->db->connect();
    }

    // destructor
    function __destruct(){

    }

    // Storing new doctor
    public function storeDoctor($_id,$firstName,$lastName,$specialization,$licenseNumber,$clinicAddress,$email,$contactNum,$username,$password,$aboutMe){
        $result = mysqli_query($this->db->connect(),"INSERT INTO doctor(_id,first_name,last_name,specialization,license_number,clinic_address,email,contact_number,username,password,about_me) VALUES('$_id','$firstName','$lastName','$specialization','$licenseNumber','$clinicAddress','$email','$contactNum','$username','$password','$aboutMe')");

        if (mysqli_connect_errno()){
            $this->error_conn = mysqli_connect_error();
        }

        if(!$result){
            if(mysqli_errno($this->db->connect()) == 1062){
                // duplicate key - primary key violation
                return true;
            } else{
                // for other reasons
                $this->error = mysqli_error($this->db->connect());
                $this->error_no = mysqli_errno($this->db->connect());
                return false;
            }
        } else{
            $this->last_id = mysqli_insert_id($this->db->connect());
            return true;
        }
    }

    // getters
    public function getError(){
        return $this->error;
    }
    public function getError_no(){
        return $this->error_no;
    }
    public function getError_conn(){
        return $this->error_conn;
    }
    ...

我在java中有一个将sqlite数据同步到mysql的函数:

public void syncSQLiteToMySQL(Context context,String selectQuery){
    dop = new DatabaseOperations(context);
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    ArrayList<HashMap<String,String>> doctorList = new ArrayList<HashMap<String,String>>();
    doctorList = dop.getAllDoctors();
    if(doctorList.size()!=0){
        String json = dop.composeJSONfromSQLite(selectQuery);
        params.put("doctorsJSON", json);
        Log.i("json to pass", json);
        client.post("http://"+ip+":8080/changed_server_name/insertuser.php",params ,new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String response) {
                Log.e("client response",response);
                try {
                    JSONArray arr = new JSONArray(response);
                    for(int i=0; i<arr.length();i++){
                        JSONObject obj = (JSONObject)arr.get(i);
                        // did something with json response here
                        dop.updateSyncStatus(obj.getString("local_id"),obj.getString("status"));
                    }
                    message = "DB Sync completed!";
                } catch (JSONException e) {
                    message = "Error Occured [Server's JSON response might be invalid]!";
                    Log.e("JSONException",e.getMessage());
                }
            }

            @Override
            public void onFailure(int statusCode, Throwable error, String content) {
                if(statusCode == 404){
                    message = "Requested resource not found";
                }else if(statusCode == 500){
                    message = "Something went wrong at server end";
                }else{
                    message = "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]";
                    Log.e("sync post failure",error.toString());
                }
            }
        });
    }
}
public void syncSQLiteToMySQL(上下文,字符串selectQuery){
dop=新数据库操作(上下文);
AsyncHttpClient=新的AsyncHttpClient();
RequestParams params=新的RequestParams();
ArrayList doctorList=新的ArrayList();
doctorList=dop.getAllDoctors();
如果(doctorList.size()!=0){
字符串json=dop.composeJSONfromSQLite(selectQuery);
参数put(“doctorsJSON”,json);
Log.i(“要传递的json”,json);
client.post(“http://“+ip+”:8080/changed_server_name/insertuser.php”),params,新的AsyncHttpResponseHandler(){
@凌驾
成功时公共无效(字符串响应){
Log.e(“客户响应”,响应);
试一试{
JSONArray arr=新JSONArray(响应);

对于(int i=0;i您是否尝试使用错误报告(E_ALL)

也在您使用的构造函数中 $this->db->connect()

然后在你用过的商店里 $result=mysqli\u query($this->db->connect()

你可以发布connect的代码吗?

我尝试了
错误报告(E\u ALL)
,但php错误日志中仍然没有发布新的错误。
public void syncSQLiteToMySQL(Context context,String selectQuery){
    dop = new DatabaseOperations(context);
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    ArrayList<HashMap<String,String>> doctorList = new ArrayList<HashMap<String,String>>();
    doctorList = dop.getAllDoctors();
    if(doctorList.size()!=0){
        String json = dop.composeJSONfromSQLite(selectQuery);
        params.put("doctorsJSON", json);
        Log.i("json to pass", json);
        client.post("http://"+ip+":8080/changed_server_name/insertuser.php",params ,new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String response) {
                Log.e("client response",response);
                try {
                    JSONArray arr = new JSONArray(response);
                    for(int i=0; i<arr.length();i++){
                        JSONObject obj = (JSONObject)arr.get(i);
                        // did something with json response here
                        dop.updateSyncStatus(obj.getString("local_id"),obj.getString("status"));
                    }
                    message = "DB Sync completed!";
                } catch (JSONException e) {
                    message = "Error Occured [Server's JSON response might be invalid]!";
                    Log.e("JSONException",e.getMessage());
                }
            }

            @Override
            public void onFailure(int statusCode, Throwable error, String content) {
                if(statusCode == 404){
                    message = "Requested resource not found";
                }else if(statusCode == 500){
                    message = "Something went wrong at server end";
                }else{
                    message = "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]";
                    Log.e("sync post failure",error.toString());
                }
            }
        });
    }
}