Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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
Sql 使用Base64和远程查询到远程数据库的问题。。(图像越大等待时间越长??)_Sql_Mysql_Sqlite_Base64 - Fatal编程技术网

Sql 使用Base64和远程查询到远程数据库的问题。。(图像越大等待时间越长??)

Sql 使用Base64和远程查询到远程数据库的问题。。(图像越大等待时间越长??),sql,mysql,sqlite,base64,Sql,Mysql,Sqlite,Base64,我有一个5Kb的图像,当我把它转换成Base64字符串并上传到我的远程数据库时,远程插入查询只需要几秒钟 但是。。我有一个100Kb的图像,当我把它转换成Base64字符串并上传到远程数据库时,远程插入查询需要很多秒才能执行 为什么? 这是因为Base64字符串需要100KB的空间,就像未编码的图像一样 有没有办法解决这些等待时间 更多信息:im使用PHP+JSOn连接到mysql远程数据库 Oded建议我不要使用Base64,使用BLOB而不是LONGTEXT但是。。。。?如何将BLOB与JS

我有一个5Kb的图像,当我把它转换成Base64字符串并上传到我的远程数据库时,远程插入查询只需要几秒钟

但是。。我有一个100Kb的图像,当我把它转换成Base64字符串并上传到远程数据库时,远程插入查询需要很多秒才能执行

为什么?

这是因为Base64字符串需要100KB的空间,就像未编码的图像一样

有没有办法解决这些等待时间

更多信息:im使用PHP+JSOn连接到mysql远程数据库

Oded建议我不要使用Base64,使用BLOB而不是LONGTEXT但是。。。。?如何将BLOB与JSON+PHP结合使用?我不知道,正如我所知,JSON+PHP需要接收和发送字符串,而BLOB不是字符串

谢谢

编辑2:

这是需要花费大量时间等待的代码(它在以下行中等待:
而((line=reader.readLine())!=null){
,它正在等待
reader.readLine()

这段代码从远程数据库获取一个用户,在我的应用程序上显示该用户需要很长时间

public Friend RetrieveOneUser(String email)
{

    Friend friend=null;

    String result = "";
    //the parameter data to send
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("email",email));

    //http post
    InputStream is=null;
    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(this.BaseURL + this.GetOneUser_URL);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
    }
    //convert response to string
    try{

            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();

            result=sb.toString();
    }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
    }

    //parse json data
    try{
            JSONArray jArray = new JSONArray(result);


            for(int i=0;i<jArray.length();i++)
            {
                    JSONObject json_data = jArray.getJSONObject(i);
                    friend=new Friend(json_data.getString("email"),json_data.getString("password"), json_data.getString("fullName"), json_data.getString("mobilePhone"), json_data.getString("mobileOperatingSystem"),"",json_data.getString("photo"));
            }
    }
    catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    }

    return friend;
}
public Friend RetrieveOneUser(字符串电子邮件)
{
Friend=null;
字符串结果=”;
//要发送的参数数据
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“email”,email));
//http post
InputStream=null;
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost-HttpPost=newhttppost(this.BaseURL+this.GetOneUser\u URL);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
is=entity.getContent();
}捕获(例外e){
e(“Log_标记”,“http连接错误”+e.toString());
}
//将响应转换为字符串
试一试{
BufferedReader reader=新的BufferedReader(新的InputStreamReader(is,“iso-8859-1”),8;
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
is.close();
结果=sb.toString();
}捕获(例外e){
Log.e(“Log_标记”,“错误转换结果”+e.toString());
}
//解析json数据
试一试{
JSONArray jArray=新JSONArray(结果);

对于(int i=0;i为什么不将图像直接存储为一个

所有转换完成的是延迟和额外的CPU时间


更新:

现在我们知道了为什么需要base64(因为JSON不能传输二进制数据),我修改了我的答案

您需要检查为什么这需要很长时间。是网络传输吗?是数据库吗?一旦您知道答案,我们就可以开始寻找解决方案。

是6位编码:传输3字节的图像需要4个字符(4字节)。因此,在Base64中存储100kb的图像需要133kb的空间


你还没有说你正在使用哪个数据库,但是如果你每行存储超过8kb,并不是所有的数据库都能运行良好。

怎么做?BLOB存储字符串?@AndroidUser99-否。BLOB存储二进制数据,例如图像数据本身。如果你告诉我们你正在使用哪个数据库,可以建议一种适当的方法。是不是相同?阅读以下内容:10。4.3.BLOB和文本类型A BLOB是一个二进制大对象,可以保存可变数量的数据。这四种BLOB类型是TINYBLOB、BLOB、MEDIUMBLOB和LONGBLOB。它们仅在可以保存的值的最大长度上有所不同。这四种文本类型是TINYTEXT、TEXT、MEDIUMTEXT和LONGTEXT。它们对应于四种BLOB类型和h保持相同的最大长度和存储要求。请参阅第10.5节“数据类型存储要求”。我对远程数据库使用MYSQL,对本地数据库使用SQLite(远程数据库的副本)@AndroidUser99-这就是我的观点。你在做不必要的工作。为什么要先转换为Base64?