Twisted_Duke has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I am beginning work on a new project which requires, in a game setting, information in a mySQL database to be changed as well as accessed. The accessing part is no problem, but I have tried to no avail to find an answer on how to change the actual information in the database through PERL. Example: Your character, Bob, currently has 0 gold belonging to him. By the grace of the local Lord or Lady, he has been awarded 100 gold for his allegience... How, in a perl setting, would this be able to be automatically changed upon this instance? This is a major factor in the project, and it would be extremely helpful if anybody could help me to find the answer. Thanks to All, The Twisted Duke

Replies are listed 'Best First'.
(shockme) Re: Database Manipulation
by shockme (Chaplain) on Dec 12, 2001 at 06:42 UTC
    Assuming that the table has a unique id, you can do something like the following:

    $dbh = DBI->connect($DSN, $user, $passwd) || die "Cannot connect: $DBI +:errstr\n"; $drh = DBI->install_driver("mysql"); ... $SQLText = "UPDATE gold SET amount = $Gold WHERE id = $goldID"; $sth = $dbh->prepare($SQLText); $query = $sth1->execute;

    You can find more information regarding Perl and MySQL here.

    If things get any worse, I'll have to ask you to stop helping me.

      Thanks a lot, this is a lifesaver.
Re: Database Manipulation
by vek (Prior) on Dec 12, 2001 at 06:48 UTC
    I've found that perldoc DBI or the fine book Programming The Perl DBI to be an invaluable help with my database activities.
      I can highly reccomend this book too. Very good (even if it is a bit boring) ;-)
Re: Database Manipulation
by cfreak (Chaplain) on Dec 12, 2001 at 21:00 UTC
    The mySQL documentation availiable at http://mysql.com/doc is very helpful too. Try searching for the INSERT or UPDATE syntax. Both of those will do what you want.

    Chris