关于php:更新错误中的语法错误

 2019-10-09 

Syntax error in update trouble

我写了那个SQL命令,但是很麻烦。 我仍然收到一些错误,现在它是:
"您的SQL语法有误;请在与MySQL服务器版本相对应的手册中找到正确的语法,以在'HALF-LIFE附近使用它,并在第1行将"磅"的组合震惊整个游戏行业"

但是我仍然不知道出什么问题了。 通过phpmyadmin处理命令正常工作,但我必须通过php发送。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$sql ="UPDATE steam_games SET description = '1998. HALF-LIFE sends a shock through the game industry with its combination of pounding action and continuous, immersive storytelling. Valve's debut title wins more than 50 game-of-the-year awards on its way to being named "Best PC Game Ever" by PC Gamer, and launches a franchise with more than eight million retail units sold worldwide.
            NOW. By taking the suspense, challenge and visceral charge of the original, and adding startling new realism and responsiveness, Half-Life 2 opens the door to a world where the player's presence affects everything around him, from the physical environment to the behaviors even the emotions of both friends and enemies.
            The player again picks up the crowbar of research scientist Gordon Freeman, who finds himself on an alien-infested Earth being picked to the bone, its resources depleted, its populace dwindling. Freeman is thrust into the unenviable role of rescuing the world from the wrong he unleashed back at Black Mesa. And a lot of people he cares about are counting on him.
            The intense, real-time gameplay of Half-Life 2 is made possible only by Source®, Valve's new proprietary engine technology. Source provides major enhancements in:
           
<ul>

           
<li>
<span class="
copyHead">Characters:</span> Advanced facial animation system delivers the most sophisticated in-game characters ever seen. With 40 distinct facial "muscles," human characters convey the full array of human emotion, and respond to the player with fluidity and intelligence.
</li>

           
<li>
<span class="
copyHead">Physics:</span> From pebbles to water to 2-ton trucks respond as expected, as they obey the laws of mass, friction, gravity, and buoyancy.
</li>

           
<li>
<span class="
copyHead">Graphics:</span> Source's shader-based renderer, like the one used at Pixar to create movies such as Toy Story&reg; and Monster's, Inc.&reg;, creates the most beautiful and realistic environments ever seen in a video game.
</li>

           
<li>
<span class="
copyHead">AI:</span> Neither friends nor enemies charge blindly into the fray. They can assess threats, navigate tricky terrain, and fashion weapons from whatever is at hand.
</li>

           
</ul>
', supported_languages = 'English*, French*, German*, Italian*, Korean*, Spanish*, Russian*, Simplified Chinese*, Traditional Chinese*, Dutch, Danish, Finnish, Japanese, Norwegian, Polish, Portuguese, Swedish, Thai**languages with full audio support', header_image = 'http://cdn2.steampowered.com/v/gfx/apps/220/header.jpg?t=1369255063', website = 'http://www.half-life2.com' WHERE appid = 220"
;


实际上,由于我确实对问题的根源发表了第一条评论,至少这是值得赞成的。

您忘了转义所有包含撇号的单词。

如您在注释中所述,使用$myString = str_replace("'","\'", $sql);并使用它来"自动化"事物,您将替换description = '1998

'中的所有撇号,其中需要一些撇号。 同一行的其余部分。

开头和结尾的撇号不能用\'代替,因为这会引发错误。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$sql ="UPDATE steam_games SET description = '1998. HALF-LIFE sends a shock through the game industry with its combination of pounding action and continuous, immersive storytelling. Valve\'s debut title wins more than 50 game-of-the-year awards on its way to being named "Best PC Game Ever" by PC Gamer, and launches a franchise with more than eight million retail units sold worldwide.
    NOW. By taking the suspense, challenge and visceral charge of the original, and adding startling new realism and responsiveness, Half-Life 2 opens the door to a world where the player\'s presence affects everything around him, from the physical environment to the behaviors even the emotions of both friends and enemies.
    The player again picks up the crowbar of research scientist Gordon Freeman, who finds himself on an alien-infested Earth being picked to the bone, its resources depleted, its populace dwindling. Freeman is thrust into the unenviable role of rescuing the world from the wrong he unleashed back at Black Mesa. And a lot of people he cares about are counting on him.
    The intense, real-time gameplay of Half-Life 2 is made possible only by Source&reg;, Valve\'s new proprietary engine technology. Source provides major enhancements in:
   
<ul>

   
<li>
<span class="
copyHead">Characters:</span> Advanced facial animation system delivers the most sophisticated in-game characters ever seen. With 40 distinct facial "muscles," human characters convey the full array of human emotion, and respond to the player with fluidity and intelligence.
</li>

   
<li>
<span class="
copyHead">Physics:</span> From pebbles to water to 2-ton trucks respond as expected, as they obey the laws of mass, friction, gravity, and buoyancy.
</li>

   
<li>
<span class="
copyHead">Graphics:</span> Source\'s shader-based renderer, like the one used at Pixar to create movies such as Toy Story&reg; and Monster\'s, Inc.&reg;, creates the most beautiful and realistic environments ever seen in a video game.
</li>

   
<li>
<span class="
copyHead">AI:</span> Neither friends nor enemies charge blindly into the fray. They can assess threats, navigate tricky terrain, and fashion weapons from whatever is at hand.
</li>

   
</ul>
', supported_languages = 'English*, French*, German*, Italian*, Korean*, Spanish*, Russian*, Simplified Chinese*, Traditional Chinese*, Dutch, Danish, Finnish, Japanese, Norwegian, Polish, Portuguese, Swedish, Thai**languages with full audio support', header_image = 'http://cdn2.steampowered.com/v/gfx/apps/220/header.jpg?t=1369255063', website = 'http://www.half-life2.com' WHERE appid = 220"
;


我强烈建议您准备替换单引号。

例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

//assuming $mysqli is a connected database

$mysqli->prepare("UPDATE steam_games SET description = ?, supported_languages = ?, header_image = ?, website = ? WHERE appid = ?");

$desc = <<<EOT

1998. HALF-LIFE sends a shock through the game industry with its combination of pounding action and continuous, immersive storytelling. Valve's debut title wins more than 50 game-of-the-year awards on its way to being named "Best PC Game Ever" by PC Gamer, and launches a franchise with more than eight million retail units sold worldwide.
            NOW. By taking the suspense, challenge and visceral charge of the original, and adding startling new realism and responsiveness, Half-Life 2 opens the door to a world where the player's presence affects everything around him, from the physical environment to the behaviors even the emotions of both friends and enemies.
            The player again picks up the crowbar of research scientist Gordon Freeman, who finds himself on an alien-infested Earth being picked to the bone, its resources depleted, its populace dwindling. Freeman is thrust into the unenviable role of rescuing the world from the wrong he unleashed back at Black Mesa. And a lot of people he cares about are counting on him.
            The intense, real-time gameplay of Half-Life 2 is made possible only by Source&reg;, Valve's new proprietary engine technology. Source provides major enhancements in:
           
<ul>

           
<li>
<span class="copyHead">Characters:</span> Advanced facial animation system delivers the most sophisticated in-game characters ever seen. With 40 distinct facial "muscles," human characters convey the full array of human emotion, and respond to the player with fluidity and intelligence.
</li>

           
<li>
<span class="copyHead">Physics:</span> From pebbles to water to 2-ton trucks respond as expected, as they obey the laws of mass, friction, gravity, and buoyancy.
</li>

           
<li>
<span class="copyHead">Graphics:</span> Source's shader-based renderer, like the one used at Pixar to create movies such as Toy Story&reg; and Monster's, Inc.&reg;, creates the most beautiful and realistic environments ever seen in a video game.
</li>

           
<li>
<span class="copyHead">AI:</span> Neither friends nor enemies charge blindly into the fray. They can assess threats, navigate tricky terrain, and fashion weapons from whatever is at hand.
</li>

           
</ul>


EOT
;

$languages = <<<EOT

English*, French*, German*, Italian*, Korean*, Spanish*, Russian*, Simplified Chinese*, Traditional Chinese*, Dutch, Danish, Finnish, Japanese, Norwegian, Polish, Portuguese, Swedish, Thai**languages with full audio support

EOT
;

$header_img ="http://cdn2.steampowered.com/v/gfx/apps/220/header.jpg?t=1369255063";
$website    ="http://www.half-life2.com";
$appid      = 220;

$mysqli->bind("ssssi", $desc, $languages, $header_img, $website, $appid);
$mysqli->execute();

?>