PHP無法寫進(jìn)mySQL
Jun 13, 2016 am 11:20 AM
PHP無法寫入mySQL
小妹是php新手
最近想要試著寫一個(gè)搜尋程式
主要是藉由php作為媒介連結(jié)android和mySQL
不過卻卡在我的php一直無法成功判讀SQL語(yǔ)法
以下是我主要問題程式片段:
(in?java)
try?{
String?result?=?DBConnector.executeQuery("SELECT*FROM?user?where?zip?=?'newzip'?");
System.out.println(result);
(php語(yǔ)法)
$db?=?mysql_pconnect("localhost","root","1234");
mysql_query("SET?CHARACTER?SET?'UTF8';");
mysql_query("SET?NAMES?UTF8;");
mysql_query("SET?CHARACTER_SET_CLIENT=UTF8;");
mysql_query("SET?CHARACTER_SET_RESULTS=UTF8;");
mysql_select_db("food");
$sql?=?$_POST["query_string"];
$res?=?mysql_query($sql);
while($r?=?mysql_fetch_assoc($res))
$output[]?=?$r;
print(json_encode($output));
mysql_close();
?>
這是我的錯(cuò)誤訊息:
mysql_fetch_assoc():?supplied?argument?is?not?a?valid?MySQL?result?resource?in?C:\AppServ\www\AndroidConnectDB\android_connect_db.php?on?line?13
我有將java中的語(yǔ)法直接在phpmyadmin中執(zhí)行
(即SELECT*FROM?user?where?zip?=?'newzip')
是可以正確找到該筆符合條件的資料
但是不知道為什麼?透過java寫入至php中去呼叫mySQL執(zhí)行時(shí)卻總是傳回錯(cuò)誤
上網(wǎng)爬過很多文
有試著去修正過編碼的問題(SET?NAMES?UTF8;)
也有去php.ini修改過?magic_quotes_gpc?=?On
但仍舊回傳null以及錯(cuò)誤訊息
但是我將它改成
SELECT*FROM?user?where?id=1?時(shí)
是可以正確執(zhí)行的00"
所以再猜想會(huì)不會(huì)是單引號(hào)引起的問題
也有將它改成
SELECT*FROM?user?where?zip?=?/'newzip/'
卻仍舊不見好轉(zhuǎn)ˊˋ
想要請(qǐng)問各位大大是否有解決的方法?ˊˋ
------解決方案--------------------
猜測(cè)是沒有用的,需要看到出錯(cuò)時(shí)的錯(cuò)誤信息
$res?=?mysql_query($sql)?or?die(mysql_error());
因?yàn)槟憬o出的錯(cuò)誤信息是
mysql_fetch_assoc():?supplied?argument?is?not?a?valid?MySQL?result?resource?
即傳遞給?mysql_fetch_assoc?的不是有效的?MySQL?資源,所以要逐步向上查找
------解決方案--------------------
你不覺得應(yīng)該是這樣嗎?
SELECT * FROM user where zip = 'newzip'
------解決方案--------------------
關(guān)閉魔術(shù)引號(hào),修改php.ini magic_quotes_gpc = Off
或者臨時(shí)對(duì)傳入字符串反轉(zhuǎn)義
$sql = stripslashes($_POST["query_string"]);?也可以應(yīng)付過來

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

PhpisstillRelevantinmodernenterpriseenvironments.1. Modernphp (7.xand8.x)? ??? ??, ??? ??, jitcompilation ? modernsyntax, mateitsuilableforlarge-scalepplications

N 1 ?? ??? ??? ?? ???? ?????? ?????? ?? ?? ????. 2. ???? ???? ???? ?? ??? ???????? ??? ??? ?? ? ??????. 3. ??? 2 ? ?? ?? Redis ?? ??? ?? ??? ?? ?? ??? ????? ??????. 4. ??? ????? ????? ????? Clear ()? ???? ???? ?????? ??? ????? ?????. 5. ?????? ??? ????? ???? ???? ? ??? ??? ?? ?? ? SQL ?? ??????. 6. ?? ??? ???? ?? ?????? ?? ?? ??? ?????? ?? ?? ?? ??? ???? ??? ??????. ORM? ???? ????? ?? ??? ????? ?? ???? ??? ???? ?? SQL ????, ??, ?? ?? ? ??? ???? ???????.

??? PHP ???? ???? ????? RabbitMQ? ???? ??? ??? ???? 1. ????? ??? ??? ?? ??? ???? ?? ???? ???????. 2. ???? ???? ?? ???? ???, ???? ???, ?? ? ?? ACK? ?????. 3. ?? ? ?? ? ??, TTL ? ?? ?? ? ?? ?? ??? ??????. 4. Supervisord? ?? ??? ???? ??? ????? ???? ??? ??? ???? ?? ?? ?? ????? ???????. ??? ????? ???? ??? ????? ???? ??? ?????.

??? PHP ?? ???? ???? ???? ?? ??? ? Docker ??? ???? ?? ?? ????? ?????. 1. PHP : 8.3-fpm-alpine? ?? ???? ???? ?? ??? ??? ??? ??????. 2. ??? ?? php.ini? ?? ??? ??? ??????, ?? ??? ??, Opcache ? JIT? ????? ?? ? ??? ??????. 3. Nginx? ??? ???? ???? ??? ??? ?? ???? ???? PHP ??? PHP-FPM?? ???? ?????. 4. ??? ??? ???? ???? ?? ???? ???? ????? ????? ??? ?? ???? ??????. 5. CRON? ?? ?? ????? ?????? ??? ?? ??; 6. ?? ?? ??? ?? ??? ??? ??????

settings.json ??? ??? ?? ?? ?? ?? ?? ??? ??? VSCODE ??? ??? ???? ? ?????. 1. ??? ?? ?? : Windows? C : \ Users \\ AppData \ Roaming \ Code \ User \ Settings.json, MacOS IS /users//library/applicationsupport/code/user/settings.json, linux? /home//.config/code/user/settings.json; 2. Workspace ?? ?? : .vscode/settings project root ????

PHP? ??? ?? ????? ?? ??? ??????????? ?? ??? ???? ?? ?? ??? ????????. 1. ?? ??? ??? ?? ??? ?? ? ?? ???? ?????. 2. ?? ???? ???? ???? ?? ? ? ???? GC? ?? ????? ???? ?????. 3. "??? ??"zval? ?? ?? ????? ???? GC_COLLECT_CYCLES ()? ?? ? ? GC? ??????. 4. ?? ?? PHP ?? ????? ??? ??? ??? ?? GC_STATUS ()? ?????? GC_COLLECT_CYCLES ()? ? ??? ???????. 5. ?? ???? ?? ??? ??? GC_DISABLE ()? ???? ?? ? ??? ????? ORM? CLER () ???? ?? DeReeference ??? ?????.

BREF? ?? PHP ???? ??? ???? ?? ?? ???? ?? ???? ?? ????? ?? ? ? ????. 1. Bref? ??? ? PHP ??? ???? ???? PHP8.3 ? ?? ??? ???? Laravel ? Symfony? ?? ??? ??? ???? ???? PHP? Awslambda? ?????. 2. ?? ???? ??? ????? : Composer? ???? BREF ??, HTTP ?? ??? ? ?? ??? ?? ?? ? ???? ???? ?? Serverless.yml ??; 3. ServerlessDeploy ??? ???? ??? ???? APIGINGWARE? ???? ???? ??? URL? ?????. 4. Lambda ??? ?? Bref? ???? ?????.

readOnlyPropertiesInphp8.2CanonlyBeassignedOnedOneDonceIntheConstructorAratDeclarationandCannotBemodififificificificifified
