我正在尝试用pdo更新mysql ...我在一个站点上工作,但它不能在第二个站点上运行。无论我尝试哪种方法,我都会收到跟随错误。
第一个网站是在网上直播的,而这个网站是在wamp ...不确定这是否重要。
(!)致命错误:在第236行的C:\ wamp \ www \ demo \ admin \ action \ global-settings-css-update.php中 (!)PDOException:在第236行的C:\ wamp \ www \ demo \ admin \ action \ global-settings-css-update.php中
<?php
$level = '../../';
//include($level.'inc/start.php');
$db_host = "localhost";
$db_username = "xxxxx";
$db_pass = "xxxxx";
$db_name = "demo";
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ));
$action = $_POST['action'];
$returnto = $_POST['returnto'];
$global_id = $_POST['global_id'];
$rem_base = $_POST['rem_base'];
$base_font_size = $_POST['base_font_size'];
$base_line_height = $_POST['base_line_height'];
$_POST_width = $_POST['_POST_width'];
$column_gutter = $_POST['column_gutter'];
$default_font_family = $_POST['default_font_family'];
$default_font_color = $_POST['default_font_color'];
$default_font_style = $_POST['default_font_style'];
$default_font_weight = $_POST['default_font_weight'];
$primary = $_POST['primary'];
$primary_lighter = $_POST['primary_lighter'];
$primary_darker = $_POST['primary_darker'];
$second_accent = $_POST['second_accent'];
$second_accent_lighter = $_POST['second_accent_lighter'];
$second_accent_darker = $_POST['second_accent_darker'];
$third_accent = $_POST['third_accent'];
$third_accent_lighter = $_POST['third_accent_lighter'];
$third_accent_darker = $_POST['third_accent_darker'];
$alert = $_POST['alert'];
$alert_lighter = $_POST['alert_lighter'];
$alert_darker = $_POST['alert_darker'];
$success = $_POST['success'];
$success_lighter = $_POST['success_lighter'];
$success_darker = $_POST['success_darker'];
$warning = $_POST['warning'];
$warning_lighter = $_POST['warning_lighter'];
$warning_darker = $_POST['warning_darker'];
$pg_bg_color = $_POST['pg_bg_color'];
$pg_has_gradient_bg = $_POST['pg_has_gradient_bg'];
$pg_bg_gradient_direction = $_POST['pg_bg_gradient_direction'];
$pg_bg_which_flow = $_POST['pg_bg_which_flow'];
$pg_bg_light_percent = $_POST['pg_bg_light_percent'];
$pg_bg_dark_percent = $_POST['pg_bg_dark_percent'];
$pg_has_bg_image = $_POST['pg_has_bg_image'];
$pg_bg_img = $_POST['pg_bg_img'];
$pg_bg_repeat = $_POST['pg_bg_repeat'];
$pg_bg_image_positioned = $_POST['pg_bg_image_positioned'];
$pg_bg_hor_align = $_POST['pg_bg_hor_align'];
$pg_bg_vert_align = $_POST['pg_bg_vert_align'];
if($action == 'add'){
$insertq = $db->prepare(
'INSERT INTO THE-TABLE (
rem_base,
base_font_size,
base_line_height,
row_width,
column_gutter,
default_font_family,
default_font_color,
default_font_style,
default_font_weight,
primary,
primary_lighter,
primary_darker,
second_accent,
second_accent_lighter,
second_accent_darker,
third_accent,
third_accent_lighter,
third_accent_darker,
alert,
alert_lighter,
alert_darker,
success,
success_lighter,
success_darker,
warning,
warning_lighter,
warning_darker,
pg_bg_color,
pg_has_gradient_bg,
pg_bg_gradient_direction,
pg_bg_which_flow,
pg_bg_light_percent,
pg_bg_dark_percent,
pg_has_bg_image,
pg_bg_img,
pg_bg_repeat,
pg_bg_image_positioned,
pg_bg_hor_align,
pg_bg_vert_align
)
VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?)');
$insertq->execute(array(
$rem_base,
$base_font_size,
$base_line_height,
$row_width,
$column_gutter,
$default_font_family,
$default_font_color,
$default_font_style,
$default_font_weight,
$primary,
$primary_lighter,
$primary_darker,
$second_accent,
$second_accent_lighter,
$second_accent_darker,
$third_accent,
$third_accent_lighter,
$third_accent_darker,
$alert,
$alert_lighter,
$alert_darker,
$success,
$success_lighter,
$success_darker,
$warning,
$warning_lighter,
$warning_darker,
$pg_bg_color,
$pg_has_gradient_bg,
$pg_bg_gradient_direction,
$pg_bg_which_flow,
$pg_bg_light_percent,
$pg_bg_dark_percent,
$pg_has_bg_image,
$pg_bg_img,
$pg_bg_repeat,
$pg_bg_image_positioned,
$pg_bg_hor_align,
$pg_bg_vert_align
));
$msg = 's|The '.$table_title.': '.$industry.' has been added to the database.';
}
elseif($action == 'edit'){
$updateq=$db->prepare("update global_settings set
global_id=:global_id,
rem_base=:rem_base,
base_font_size=:base_font_size,
base_line_height=:base_line_height,
row_width=:row_width,
column_gutter=:column_gutter,
default_font_family=:default_font_family,
default_font_color=:default_font_color,
default_font_style=:default_font_style,
default_font_weight=:default_font_weight,
primary=:primary,
primary_lighter=:primary_lighter,
primary_darker=:primary_darker,
second_accent=:second_accent,
second_accent_lighter=:second_accent_lighter,
second_accent_darker=:second_accent_darker,
third_accent=:third_accent,
third_accent_lighter=:third_accent_lighter,
third_accent_darker=:third_accent_darker,
alert=:alert,
alert_lighter=:alert_lighter,
alert_darker=:alert_darker,
success=:success,
success_lighter=:success_lighter,
success_darker=:success_darker,
warning=:warning,
warning_lighter=:warning_lighter,
warning_lighter=:warning_lighter,
pg_bg_color=:pg_bg_color,
pg_has_gradient_bg=:pg_has_gradient_bg,
pg_bg_gradient_direction=:pg_bg_gradient_direction,
pg_bg_which_flow=:pg_bg_which_flow,
pg_bg_light_percent=:pg_bg_light_percent,
pg_bg_dark_percent=:pg_bg_dark_percent,
pg_has_bg_image=:pg_has_bg_image,
pg_bg_img=:pg_bg_img,
pg_bg_repeat=:pg_bg_repeat,
pg_bg_image_positioned=:pg_bg_image_positioned,
pg_bg_hor_align=:pg_bg_hor_align,
pg_bg_vert_align=:pg_bg_vert_align
where global_id=$global_id");
$updateq->bindParam(':global_id',$global_id,PDO::PARAM_STR);
$updateq->bindParam(':rem_base',$rem_base,PDO::PARAM_STR);
$updateq->bindParam(':base_font_size',$base_font_size,PDO::PARAM_STR);
$updateq->bindParam(':base_line_height',$base_line_height,PDO::PARAM_STR);
$updateq->bindParam(':row_width',$row_width,PDO::PARAM_STR);
$updateq->bindParam(':column_gutter',$column_gutter,PDO::PARAM_STR);
$updateq->bindParam(':default_font_family',$default_font_family,PDO::PARAM_STR);
$updateq->bindParam(':default_font_color',$default_font_color,PDO::PARAM_STR);
$updateq->bindParam(':default_font_style',$default_font_style,PDO::PARAM_STR);
$updateq->bindParam(':default_font_weight',$default_font_weight,PDO::PARAM_STR);
$updateq->bindParam(':primary',$primary,PDO::PARAM_STR);
$updateq->bindParam(':primary_lighter',$primary_lighter,PDO::PARAM_STR);
$updateq->bindParam(':primary_darker',$primary_darker,PDO::PARAM_STR);
$updateq->bindParam(':second_accent',$second_accent,PDO::PARAM_STR);
$updateq->bindParam(':second_accent_lighter',$second_accent_lighter,PDO::PARAM_STR);
$updateq->bindParam(':second_accent_darker',$second_accent_darker,PDO::PARAM_STR);
$updateq->bindParam(':third_accent',$third_accent,PDO::PARAM_STR);
$updateq->bindParam(':third_accent_lighter',$third_accent_lighter,PDO::PARAM_STR);
$updateq->bindParam(':third_accent_darker',$third_accent_darker,PDO::PARAM_STR);
$updateq->bindParam(':alert',$alert,PDO::PARAM_STR);
$updateq->bindParam(':alert_lighter',$alert_lighter,PDO::PARAM_STR);
$updateq->bindParam(':alert_darker',$alert_darker,PDO::PARAM_STR);
$updateq->bindParam(':success',$success,PDO::PARAM_STR);
$updateq->bindParam(':success_lighter',$success_lighter,PDO::PARAM_STR);
$updateq->bindParam(':success_darker',$success_darker,PDO::PARAM_STR);
$updateq->bindParam(':warning',$warning,PDO::PARAM_STR);
$updateq->bindParam(':warning_lighter',$warning_lighter,PDO::PARAM_STR);
$updateq->bindParam(':warning_lighter',$warning_lighter,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_color',$pg_bg_color,PDO::PARAM_STR);
$updateq->bindParam(':pg_has_gradient_bg',$pg_has_gradient_bg,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_gradient_direction',$pg_bg_gradient_direction,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_which_flow',$pg_bg_which_flow,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_light_percent',$pg_bg_light_percent,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_dark_percent',$pg_bg_dark_percent,PDO::PARAM_STR);
$updateq->bindParam(':pg_has_bg_image',$pg_has_bg_image,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_img',$pg_bg_img,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_repeat',$pg_bg_repeat,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_image_positioned',$pg_bg_image_positioned,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_hor_align',$pg_bg_hor_align,PDO::PARAM_STR);
$updateq->bindParam(':pg_bg_vert_align',$pg_bg_vert_align,PDO::PARAM_STR);
$updateq->execute();
$msg = 's|The '.$table_title.': '.$industry.' has been updated in the database.';
}
echo '<Script language="javascript">window.location="'.$level.'admin/global-settings-css-action.php?msg='.$msg.'"</script>';
?>
谢谢, 皮特
答案 0 :(得分:5)
首先, primary
是MySQL保留字:
<强> http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html 强>
需要用反引号包裹;你在两个例子中使用它。
另一种选择是将其命名为primary
以外的其他内容。
$insertq = $db->prepare(
'INSERT INTO THE-TABLE (
rem_base,
base_font_size,
base_line_height,
row_width,
column_gutter,
default_font_family,
default_font_color,
default_font_style,
default_font_weight,
`primary`,
并在:
$updateq=$db->prepare("update global_settings set
global_id=:global_id,
rem_base=:rem_base,
base_font_size=:base_font_size,
base_line_height=:base_line_height,
row_width=:row_width,
column_gutter=:column_gutter,
default_font_family=:default_font_family,
default_font_color=:default_font_color,
default_font_style=:default_font_style,
default_font_weight=:default_font_weight,
`primary`=:primary,
我不确定$_POST_width = $_POST['_POST_width'];
可能会产生不良/意外影响,因为superglobals以$_
开头(实际上是9个中的8个)。
我建议您将$_POST_width
重命名为$_
以外的其他内容。
我无法100%确定这一点,但如果你仍然遇到错误,那值得一试。
你需要告诉我这是如何吸引来的。
据我所知,它可能需要$row_width = $_POST['width'];
,具体取决于您的表单元素的名称。
您需要向我提供您的HTML表单才能确定。