我想將我的資料庫資料匯出成.txt檔案格式
這是我上網看教學的可是他不會跑 請幫幫我
<?php
require_once("SQL_data.php");
$insert_new2=$_POST['date'];
$insert_new1="Y";
$insert_new0=$_POST['id'];
mysql_select_db($database,$GD);
$sql=sprintf("SELECT * INTO OUTFILE 'htdocs:/image/test.txt' FROM b17_25153459_people.app_shop_for_cart;");
$Result=mysql_query($sql,$GD) or die(mysql_error());
mysql_close();
exit();
?>
SQL_data
<?php
$hostname="";
$username="";
$password="";
$database="b17_25153459_people";
$GD=mysql_pconnect($hostname,$username,$password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("SET NAMES UTF8");
mysql_query("SET CHARACTER_SET_CLIENT='utf8'");
mysql_query("SET CHARACTER_SET_RESULTS='utf8'");
?>
權限
我的錯誤代碼 檢查過了一次 他沒寫哪裡有問題
StrictMode policy violation; ~duration=862 ms: android.os.strictmode.NetworkViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1570)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:115)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at cz.msebera.android.httpclient.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:259)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159)
at cz.msebera.android.httpclient.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:879)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.example.useweb0204.Upphp_shop_buy.Interting(Upphp_shop_buy.java:29)
at com.example.useweb0204.tab3$5$1.onClick(tab3.java:240)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
StrictMode policy violation; ~duration=862 ms: android.os.strictmode.NetworkViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1570)
at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:198)
at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at cz.msebera.android.httpclient.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:259)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159)
at cz.msebera.android.httpclient.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:879)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.example.useweb0204.Upphp_shop_buy.Interting(Upphp_shop_buy.java:29)
at com.example.useweb0204.tab3$5$1.onClick(tab3.java:240)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
D/StrictMode: StrictMode policy violation; ~duration=836 ms: android.os.strictmode.NetworkViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1570)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:389)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at cz.msebera.android.httpclient.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:879)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.example.useweb0204.Upphp_shop_buy.Interting(Upphp_shop_buy.java:29)
at com.example.useweb0204.tab3$5$1.onClick(tab3.java:240)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
StrictMode policy violation; ~duration=836 ms: android.os.strictmode.NetworkViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1570)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:135)
at libcore.io.ForwardingOs.connect(ForwardingOs.java:95)
at libcore.io.IoBridge.connectErrno(IoBridge.java:157)
at libcore.io.IoBridge.connect(IoBridge.java:135)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at cz.msebera.android.httpclient.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:879)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.example.useweb0204.Upphp_shop_buy.Interting(Upphp_shop_buy.java:29)
at com.example.useweb0204.tab3$5$1.onClick(tab3.java:240)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
D/StrictMode: StrictMode policy violation; ~duration=475 ms: android.os.strictmode.NetworkViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1570)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:116)
at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
at cz.msebera.android.httpclient.impl.io.AbstractSessionOutputBuffer.flushBuffer(AbstractSessionOutputBuffer.java:159)
at cz.msebera.android.httpclient.impl.io.AbstractSessionOutputBuffer.flush(AbstractSessionOutputBuffer.java:166)
at cz.msebera.android.httpclient.impl.io.ContentLengthOutputStream.flush(ContentLengthOutputStream.java:101)
at cz.msebera.android.httpclient.entity.StringEntity.writeTo(StringEntity.java:170)
at cz.msebera.android.httpclient.entity.HttpEntityWrapper.writeTo(HttpEntityWrapper.java:96)
at cz.msebera.android.httpclient.impl.client.EntityEnclosingRequestWrapper$EntityWrapper.writeTo(EntityEnclosingRequestWrapper.java:112)
at cz.msebera.android.httpclient.impl.entity.EntitySerializer.serialize(EntitySerializer.java:117)
at cz.msebera.android.httpclient.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:265)
at cz.msebera.android.httpclient.impl.conn.ManagedClientConnectionImpl.sendRequestEntity(ManagedClientConnectionImpl.java:203)
at cz.msebera.android.httpclient.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
at cz.msebera.android.httpclient.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:122)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:879)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.example.useweb0204.Upphp_shop_buy.Interting(Upphp_shop_buy.java:29)
at com.example.useweb0204.tab3$5$1.onClick(tab3.java:240)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
StrictMode policy violation; ~duration=474 ms: android.os.strictmode.NetworkViolation
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1570)
at java.net.SocketInputStream.read(SocketInputStream.java:175)
at java.net.SocketInputStream.read(SocketInputStream.java:144)
at cz.msebera.android.httpclient.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160)
at cz.msebera.android.httpclient.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)
at cz.msebera.android.httpclient.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273)
at cz.msebera.android.httpclient.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at cz.msebera.android.httpclient.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at cz.msebera.android.httpclient.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at cz.msebera.android.httpclient.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
at cz.msebera.android.httpclient.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
at cz.msebera.android.httpclient.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:197)
at cz.msebera.android.httpclient.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at cz.msebera.android.httpclient.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)
at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:879)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.example.useweb0204.Upphp_shop_buy.Interting(Upphp_shop_buy.java:29)
at com.example.useweb0204.tab3$5$1.onClick(tab3.java:240)
at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
D/EGL_emulation: eglMakeCurrent: 0xd641a0c0: ver 3 0 (tinfo 0xbc6d9f60)
I/Choreographer: Skipped 61 frames! The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xd641a0c0: ver 3 0 (tinfo 0xbc6d9f60)
I/OpenGLRenderer: Davey! duration=1198ms; Flags=0, IntendedVsync=8841665064259, Vsync=8842681730885, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=8842696438139, AnimationStart=8842696512439, PerformTraversalsStart=8842696632339, DrawStart=8842773104439, SyncQueued=8842773596139, SyncStart=8842775211639, IssueDrawCommandsStart=8842775523539, SwapBuffers=8842777881239, FrameCompleted=8842864718339, DequeueBufferDuration=112000, QueueBufferDuration=244000,
為什麼你的錯誤訊息是android?
你是在Android上面執行嗎?
你在電腦上面執行可以嗎?
而且不是應該是
SELECT * FROM `table` INTO OUTFILE '{filename}';
還是說其實都可以?
我的意思是我用手機跑php
痾 錯誤 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''app_shop_for_cart' INTO OUTFILE 'test.txt'' at line 1
你的意思是這樣嗎?
$sql=sprintf("SELECT * FROM 'app_shop_for_cart' INTO OUTFILE '{test.txt}' ");
我試過直接跑 一樣跑不出來
Access denied for user 'b17_25153459'@'192.168.%' (using password: YES)
這個錯誤訊息是你連不上MySql,
有可能是帳號密碼錯誤或設定錯誤之類的,
可能要先從MySql權限上去解決.
那個
$Result=mysql_query($sql,$GD) or die(mysql_error());
改成
$Result=mysql_query($GD,$sql) or die(mysql_error());
試試,這樣應該能連到資料庫
現在看來你連資料庫都沒連到
感謝回覆這段"Access denied for user 'b17_25153459'@'192.168.%' (using password: YES)"消失了
可是我看ftp 檔案沒出現
<?php
require_once("SQL_data.php");
//$insert_new2=$_POST['date'];
//$insert_new1="Y";
//$insert_new0=$_POST['id'];
mysql_select_db($database,$GD);
//$sql=sprintf("UPDATE app_shop_for_cart SET buy='%s',order_date='%s' WHERE user_id='%s' and order_date is null ",$insert_new1,$insert_new2,$insert_new0);
$sql=sprintf("SELECT * FROM 'app_shop_for_cart' INTO OUTFILE '{history.txt}' ");
$Result=mysql_query($GD,$sql) or die(mysql_error());
mysql_close();
exit();
?>
SELECT * FROM 'app_shop_for_cart' INTO OUTFILE '/htdocs/image/history.txt'
這行我試過了 也不行:(
SELECT * FROM 'app_shop_for_cart' INTO OUTFILE '/htdocs/image/history.txt'
你現在是要把sql轉txt檔並且存到手機沒錯吧?
如果試不起來,可以換個方式
你把資料讀到手機,再寫成TXT這樣應該也OK吧?
可以試試看
我覺得你要先學會釐清問題
感謝回覆這段"Access denied for user 'b17_25153459'@'192.168.%' (using password: YES)"消失了
所以 你的 mysql_select_db($database,$GD);
return 是 true?
如果是 再來下個步驟
我看 mysql_query 的函數是這樣用的 mysql_query( $sql,$connect );
你的 sql 跟 connect 是確定的?
$Result=mysql_query($GD,$sql) or die(mysql_error());
$Result 是 true false 還是 error?
我是要把資料轉成TXT檔 在丟到我要的空間
我試過兩種方式
一、是直接整個資料庫轉TXT再放入網路空間(目前問題所在)
二、將裡面資料輸入到手機的一個STRING裡在讓手機開一個TXT檔案在塞進去(目前問題是沒辦法上傳到空間)
SELECT * INTO OUTFILE 'C:/Users/ASUS/Documents/XXX.txt' FROM test.tes
test=>資料庫名
tes=>資料表
試試看,我再localhost試OK
因為目前試都失敗 我在想是不是這個免費空間有問題
請問如果改放在google雲端可以嗎?
就是改方法二這樣的 先創建一個.txt的檔案 在將檔案存到雲端去
根據我的實驗,無法
他拒絕讓我寫入....
Can't create/write to file 'https:\\drive.google......' (Errcode: 13 "Permission denied")
開啟新 phpMyAdmin 視窗