-4

我写了那个 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";
4

2 回答 2

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();

?>
于 2013-06-29T00:20:20.683 回答
1

实际上,由于我确实就问题所在给出了第一条评论,因此至少值得一票。

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

在 using 中$myString = str_replace("'", "\'", $sql);,正如您在评论中所说并使用它来“自动化”事情,您正在替换 ALL apostrophes,其中一些撇号是需要的,在同一行的其余部分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";
于 2013-06-29T00:30:50.920 回答