名称键值 。 。 。 。 。 。 用户名进行更新Perl DBI mysql更新
#!/usr/bin/perl -w
# Use the DBI module
use strict;
use warnings;
use DBI;
# CONFIG VARIABLES
my $platform = "mysql";
my $database = "prod";
my $host = "localhost";
my $username = "root";
my $password = "admin";
# DATA SOURCE NAME
my $dsn = "dbi:$platform:$database:$host";
# PERL DBI CONNECT
my $connect = DBI->connect($dsn, $username, $password);
# VARS for Examples
my $query;
my $query_handle;
my $id;
my $demo;
# Example 2 using do() UPDATE
# SAMPLE VARIABLE AND VALUES TO PASS INTO SQL STATEMENT
$id = "username";
$name = "Arty";
# do() THE UPDATE
$query = "UPDATE jos_config SET values = '$name' WHERE namekey = $id;";
$query_handle = $connect->prepare($query);
# EXECUTE THE UPDATE
$query_handle = $connect->do($query);
print STDERR "ERROR: $DBI::errstr";
print STDERR "INFO: $query_handle rows updated";
undef $query;
错误消息:
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'values = 'Arty' WHERE namekey = smtp_username' at line 1 at /home/arty/Documents/SmtpDbchange2.pl line 40.
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'values = 'Arty' WHERE namekey = smtp_username' at line 1Use of uninitialized value $query_handle in concatenation (.) or string at /home/arty/Documents/SmtpDbchange2.pl line 43.
请协助
如果你调用'做($查询)'那么你并不需要调用'准备($查询)','做( )'在语句执行之前就准备好了。 –
推荐'DBI-> connect($ dsn,$ u,$ p,{RaiseError => 1})' - 这会为你带来错误。例如,它会在你的(多余的)'prepare()'中出现语法错误。 – pilcrow