Click here to get back home

DBI Mysql insert problem

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
DBI Mysql insert problem Yuri Shtil 10-12-2007
Posted by Yuri Shtil on October 12, 2007, 6:18 pm
Please log in for more thread options
The start field in an MYsql table is defined as follows:
start TIMESTAMP

I am using DBi::Mysql and am trying to update a column as follows:

$sth = $dbh->prepare_cached('update tests set start=? where db_id=?');
$sth->execute('NULL', 1);

The last statement returns 1 (one row updated), but I cannot see it it the
database.

What I noticed also, the server connection goes away after a number of like
updates issued, however the server logs show nothing about update statements.
Something fishy is going on on the client side.

Using $dbh->do('update tests set start=NULL where db_id=1') works,
doing the same from a command line works as well.

I am using perl v5.8.8 built for i686-linux, DBI version 1.58, DBD::mysql
version 4.005, MySQL Version: MySQL 5.0.45-community-log.

Any clues ?

Posted by Paul Lalli on October 12, 2007, 7:40 pm
Please log in for more thread options
> The start field in an MYsql table is defined as follows:
> start TIMESTAMP
>
> I am using DBi::Mysql

There is no such module. Did you perhaps mean DBI and DBD::mysql?

> and am trying to update a column as follows:
>
> $sth = $dbh->prepare_cached('update tests set start=? where db_id=?');
> $sth->execute('NULL', 1);

That says to update the tests table and set start equal to the four-
character string 'NULL', not to the special database value NULL.

> The last statement returns 1 (one row updated),

No. execute() does not return the number of rows updated. Have you
read the documentation for the module you're using?

perldoc DBI
"execute"
$rv = $sth->execute or die $sth->errstr;
$rv = $sth->execute(@bind_values) or die $sth->errstr;

Perform whatever processing is necessary to execute the
prepared statement. An "undef" is returned if an error
occurs. A successful "execute" always returns true
regardless of the number of rows affected, even if it's
zero (see below). It is always important to check the
return status of "execute" (and most other DBI methods)
for errors if you're not using "RaiseError".
[...]
"rows"
$rv = $sth->rows;

Returns the number of rows affected by the last row
affecting command, or -1 if the number of rows is not
known or not available.


> but I cannot see it it the database.
>
> What I noticed also, the server connection goes away after a
> number of like updates issued, however the server logs show
> nothing about update statements.
> Something fishy is going on on the client side.

"Something fishy" is going on in your code.

> Using $dbh->do('update tests set start=NULL where db_id=1') works,

Of course it does. But would you expect
UPDATE tests SET start='NULL' WHERE db_id = 1;
to work as well?

> Any clues ?

Read the documentation for the modules you're using. Again from
perldoc DBI:
NULL Values

Undefined values, or "undef", are used to indicate NULL
values. You can insert and update columns with a NULL value
as you would a non-NULL value. These examples insert and
update the column "age" with a NULL value:

$sth = $dbh->prepare(qq{
INSERT INTO people (fullname, age) VALUES (?, ?)
});
$sth->execute("Joe Bloggs", undef);

$sth = $dbh->prepare(qq{
UPDATE people SET age = ? WHERE fullname = ?
});
$sth->execute(undef, "Joe Bloggs");


Paul Lalli


Similar ThreadsPosted
Problem with DBD-mysql November 20, 2004, 2:34 am
DBD::mysql problem November 24, 2004, 12:24 am
problem installing DBD-mysql January 10, 2005, 5:51 pm
Problem with set_sql in Class::DBI::Loader::mysql March 22, 2006, 2:47 pm
Mysql-DBD Perl module Installation Problem in HPUX June 30, 2005, 9:05 am
[RESOLVED] DBD::mysql unresolved symbol _intel_fast_memcpy & mysql-standard-5.0.22-linux-i686-icc-glibc23 August 29, 2006, 6:33 pm
MySQL 5.0 and Perl DBD-MySQL December 3, 2005, 1:10 am
DBD:mysql doesn't read mysql option file /etc/my.cnf file January 27, 2005, 11:19 pm
DBD::mysql and UTF-8 August 13, 2005, 11:27 am
To install mysql for DBI in Perl 5.6 May 3, 2005, 2:28 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap