Cron help

oiwio

New Member
Messages
214
Reaction score
0
Points
0
Ive asked a couple times about a cron here, but those were all before we got the built-in perl modules. So, can anyone help me finish this?

Right now Im getting the error "syntax error at /home/oiwio/public_html/hpup2.pl line 14, near "use "/home/oiwio/perl/DBD::mysql""
Execution of /home/oiwio/public_html/hpup2.pl aborted due to compilation errors."

It is supposed to add 1 to all hp's every 15 minutes

Code:
#!/usr/bin/perl


# PERL MODULE WE WILL BE USING
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
     if (-d $homedir . '/perl' . $INC[$i]) {
         unshift(@INC,$homedir . '/perl' . $INC[$i]);
         $n_inc++;
         $i++;
     }
}
use DBI;

print "Content-type: text/html \n\n";


# MySQL CONFIG VARIABLES
$host = "localhost";
$database = "oiwio_oiwio";
$tablename = "users";
$user = "oiwio_oiwio";
$pw = "Fishonfire88";


# PERL MYSQL CONNECT 
$connect = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $pw, {RaiseError => 1});


$connect->selectdb($database);


SETVALUES ($hp) = $hp + 1;


$myquery = "INSERT INTO
$tablename (username, hp)
VALUES (*, $hp)";


$execute = $connect->query($myquery);

Help would be much appreciated
 
Last edited:

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
Hi oiwio:

I assume that this is the instruction on the CPanel when you install the module for DBD::mysql.

Code:
# PERL MODULE WE WILL BE USING
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
     if (-d $homedir . '/perl' . $INC[$i]) {
         unshift(@INC,$homedir . '/perl' . $INC[$i]);
         $n_inc++;
         $i++;
     }
}

So the error come from this line :
Code:
use "/home/oiwio/perl/DBD::mysql";

Try to change this to
Code:
use DBI;

you may also use the one below:

Code:
use DBD::mysql;


Instead of using the line :
Code:
$connect = [B]Mysql->connect[/B]($hostname, $database, $user, $pw);

you will have to use the DBI->connect. Please note that the parameter being used here is different from the one you use above on mysql->connect. That one looks like a function parameter for php-mysql library:). For reference on using the DBD::mysql module, please refer to this CPAN documentation.

HTH.
 

oiwio

New Member
Messages
214
Reaction score
0
Points
0
I looked at the site you suggested and got some stuff

ok, now Im getting "Can't locate object method "selectdb" via package "DBI::db" at /home/oiwio/public_html/hpup2.pl line 31.Content-type: text/html"

line 31 is "$connect->selectdb($database);"

Thanks for your help before, I think its almost working

Ill update the script in the first post
 
Last edited:

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
line 31 is "$connect->selectdb($database);"

Hi oiwio,

Definitely this will give you an error for selectdb method doesnt exist in the DBD::mysql module.

Please note also that the from your code:
Code:
$connect = DBI->connect("DBI:mysql:[B]database=$database;[/B]host=$host", $user, $pw, {RaiseError => 1});
the keyword database with its value there there in the attributes you are selecting the db to use.

Also the query method you've used here :
Code:
$execute = $connect->query($myquery);
does not exists in the DBD::mysql module.

I would suggest to use the execute() method for this.

I believe it might help if i give another link such as this.
The link i gave might be obsolete but It is still helpful though.

HTH
 
Last edited:

oiwio

New Member
Messages
214
Reaction score
0
Points
0
ok, the next error is "Can't modify non-lvalue subroutine call at /home/oiwio/public_html/hpup2.pl line 32.Content-type: text/html"

Im just taking a guess, but is this becuase $hp is not set as "hp" from the database table?


EDIT: I looked at the first site again and found this

Code:
$sth = $connect->prepare("SELECT * FROM users");
while ($ref = $sth->fetchrow_hashref()) {
    SETVALUES $hp = ('hp') + 1;

myquery = "INSERT INTO
$tablename (username, hp)
VALUES (*, $hp)";


$myquery->execute();
  }

not sure if it will work, and I dont know where the $ref comes from on the site's script or my script

I also dont have time to try it as I have to go.'


UPDATE:getting the error "Can't modify constant item in scalar assignment at /home/oiwio/public_html/hpup2.pl line 34, near ""INSERT INTO $tablename (hp) VALUES ($hp)";"Execution of /home/oiwio/public_html/hpup2.pl aborted due to compilation errors."
 
Last edited:

oiwio

New Member
Messages
214
Reaction score
0
Points
0
ok, this is the script so far
Code:
#!/usr/bin/perl


# PERL MODULE WE WILL BE USING
my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
     if (-d $homedir . '/perl' . $INC[$i]) {
         unshift(@INC,$homedir . '/perl' . $INC[$i]);
         $n_inc++;
         $i++;
     }
}
use DBI;

print "Content-type: text/html \n\n";


# MySQL CONFIG VARIABLES
$host = "localhost";
$database = "oiwio_oiwio";
$tablename = "users";
$user = "oiwio_oiwio";
$pw = "*******";


# PERL MYSQL CONNECT 
$connect = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $pw, {RaiseError => 1});

$sth = $connect->prepare("SELECT * FROM users");
$sth->execute() or die $dbh->errstr;
while ($ref = $sth->fetchrow_hashref()) {
my $hp = $ref->{'hp'} + 1;

$myquery = "UPDATE users SET hp = '$hp' WHERE username = '$ref'";

#myquery = "INSERT INTO $tablename (hp) VALUES ($hp)";


$myquery->execute();
  }

And this is the error Im now getting "Can't locate object method "execute" via package "UPDATE users SET hp = '100103' WHERE username = 'HASH(0x8a13390)'" (perhaps you forgot to load "UPDATE users SET hp = '100103' WHERE username = 'HASH(0x8a13390)'"?) at /home/oiwio/public_html/hpup2.pl line 40.Content-type: text/html"

Im not sure what it means by loading the update


UPDATE: I kept looking at the pages you suggested and googling answers and finally was able to finish the script. Thanks for all your help jose
 
Last edited:

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
Hello oiwo,
My apologies for taking too long for a reply. I've been offline for quite some time. Kindly review your script, you may notice that $myquery is a string, thus it cannot have an execute() method.

You may define the $myquery then as a dbi object. Here i'm using the connect object which was defined on the previous line.

Thus from :

Code:
$myquery = "UPDATE users SET hp = '$hp' WHERE username = '$ref'";
#myquery = "INSERT INTO $tablename (hp) VALUES ($hp)";
$myquery->execute();

i suggest you change it to:

Code:
$myquery = $connect->prepare("UPDATE users SET hp = '$hp' WHERE username = '$ref->{username}'");
$myquery ->execute();

Please note the modified : '$ref->{username}'

Thanks, HTH.
 
Last edited:
Top