更新故障中的语法错误

时间:2013-06-28 23:48:36

标签: php mysqli

我写了那个SQL命令,但我很烦恼。我仍然收到一些错误,现在它: “你的SQL语法有错误;请查看与你的MySQL服务器版本相对应的手册,以便使用正确的语法'HALF-LIFE在游戏行业中通过第1行的poundi组合发送震撼”

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

$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.<br><br>
            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.<br><br>
            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.<br><br>
            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:<br><br>
            <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<strong>*</strong>, French<strong>*</strong>, German<strong>*</strong>, Italian<strong>*</strong>, Korean<strong>*</strong>, Spanish<strong>*</strong>, Russian<strong>*</strong>, Simplified Chinese<strong>*</strong>, Traditional Chinese<strong>*</strong>, Dutch, Danish, Finnish, Japanese, Norwegian, Polish, Portuguese, Swedish, Thai<strong>*</strong><br><strong>*</strong>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";

2 个答案:

答案 0 :(得分:1)

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

示例:

<?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.<br><br>
            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.<br><br>
            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.<br><br>
            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:<br><br>
            <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<strong>*</strong>, French<strong>*</strong>, German<strong>*</strong>, Italian<strong>*</strong>, Korean<strong>*</strong>, Spanish<strong>*</strong>, Russian<strong>*</strong>, Simplified Chinese<strong>*</strong>, Traditional Chinese<strong>*</strong>, Dutch, Danish, Finnish, Japanese, Norwegian, Polish, Portuguese, Swedish, Thai<strong>*</strong><br><strong>*</strong>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();

?>

答案 1 :(得分:1)

实际上,由于我确实给出了关于问题所在位置的第一个评论,所以这至少值得投票。

你忘了逃避包含撇号的所有单词。

在使用$myString = str_replace("'", "\'", $sql);时,正如您在评论中所述并使用它来“自动化”事物,您正在替换所有撇号,其中需要一些撇号, description = '1998</ul>'以及同一行的其余部分。

开始和结束撇号不能被\'替换,因为这会给你带来错误。

$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.<br><br>
    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.<br><br>
    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.<br><br>
    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:<br><br>
    <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<strong>*</strong>, French<strong>*</strong>, German<strong>*</strong>, Italian<strong>*</strong>, Korean<strong>*</strong>, Spanish<strong>*</strong>, Russian<strong>*</strong>, Simplified Chinese<strong>*</strong>, Traditional Chinese<strong>*</strong>, Dutch, Danish, Finnish, Japanese, Norwegian, Polish, Portuguese, Swedish, Thai<strong>*</strong><br><strong>*</strong>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";