An unfinished system to manage all your paper documentation in an easy way.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package Autodoc;
  2. use strict;
  3. use JSON;
  4. use DBI;
  5. use warnings 'all';
  6. use Exporter 'import';
  7. our @EXPORT = qw(sqlconnect sqlquery load_conf);
  8. sub load_conf {
  9. my($file) = @_;
  10. my $x='';
  11. die "No configuration file given" if !defined $file;
  12. open(F,"$file") || die "Failed to load configuration file";
  13. while(<F>) { $x.=$_; }
  14. close(F);
  15. return from_json($x);
  16. }
  17. sub sqlconnect {
  18. my($sql) = @_;
  19. my $dsn = "DBI:mysql:database=$sql->{base};host=$sql->{host}";
  20. my $dbh = DBI->connect($dsn, $sql->{user}, $sql->{pass}, {
  21. mysql_enable_utf8 => 1
  22. }) || die "Failed to connect to database";
  23. return $dbh;
  24. }
  25. sub sqlquery {
  26. my $dbh = shift;
  27. my $query = shift;
  28. my @args = @_;
  29. #print STDERR "$query\n";
  30. my $sth = $dbh->prepare($query) || die "Failed to execute SQL query";
  31. $sth->execute(@args) || die "Failed to execute SQL query";
  32. return $sth;
  33. }
  34. return 1;