Skip to main content

Querying the Eximstats database - file is encrypted or is not a database

Comments

8 comments

  • cPanelMichael
    Hello Paddy, Can you try using the direct path to the sqlite3 binary that's provided as part of cPanel & WHM to see if that makes a difference? For example, instead of entering "sqlite3", you'd enter: /usr/local/cpanel/3rdparty/bin/sqlite3
    Let me know if this makes a difference. Thank you.
    0
  • MrJingles
    Hi Michael, thanks for the follow-up and my apologies for the length of this post - I want to provide as much information as possible... I'm not entirely sure how I can do what you have suggested in my php scripts. Are you able to assist? As mentioned I've tried it in numerous ways and I'll try to give you the appropriate code snippets I'm using so maybe you can point me in the right direction: My php code (without using perl or PDO) is basically as follows: $sqldb = "/location/of/copied/database/eximstats_db.sqlite3"; $sql3db = new Sqlite3($sqldb); $sql3results = $sql3db->query('SELECT * FROM failures');
    This basically shows an empty results set on my production server and $sql3db->lastErrorMsg() shows 'file is encrypted or is not a database '. I cannot see how I can call the sqlite3 binary in this code! My php code using PERL is as follows (copied / modified from the github example provided above): $perlscript = "/location/of/perscript/perl_eximstats.pl"; $query ="SELECT * FROM failures"; $command = "perl " . $perlscript . ' "' . $query . '"'; $json_records = json_encode(system($command)); echo $json_records . " \n";
    The PERL script it calls is also taken / modified from the github example (I've include it up until it fails) use strict; use JSON; use CGI; use DBD::SQLite(); my $driver = "SQLite"; my $database = "/location/of/copied/database/eximstats_db.sqlite3"; my $dsn = "DBI:$driver:dbname=$database"; my $dbh = DBI->connect($dsn,, undef, undef, { sqlite_open_flags => "DBD::SQLite::OPEN_READONLY", sqlite_use_immediate_transaction => 0, RaiseError => 1, PrintWarn => 0, } )or die $DBI::errstr; if ( not $dbh or $DBI::errstr ) { my $err = $DBI::errstr // q{something went wrong}; print $err."\n"; die qq{$err\n}; } # Grab the query from the function argument. my ($query) = @ARGV; my $sth = $dbh->prepare( $query );
    This basically errors stating 'DBD::SQLite::db prepare failed: file is encrypted or is not a database'. I have tried changing the line in the above code as follows: my $driver = "/usr/local/cpanel/3rdparty/bin/SQLite";
    This however returned the error: "Can't connect to data source 'DBI:/usr/local/cpanel/3rdparty/bin/SQLite:dbname=/location/of/copied/database/eximstats_db.sqlite3' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set)" I also tried changing the 'use DBD::SQLite();' line in the perl script to: use DBI::SQLite();
    This resulted in the following error: "Can't locate DBI/SQLite.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)". Again, I cannot see how I can call the sqlite3 binary in this code! My php code snippet using PDO is as follows: $sql3db = new PDO('sqlite:/location/of/copied/database/eximstats_db.sqlite3'); $sql3results = $sql3db->query('SELECT * FROM failures');
    This also errored but I didn't catch the error, it just didn't return any results. I tried changing the code to: $sql3db = new PDO('/usr/local/cpanel/3rdparty/bin/sqlite:/location/of/copied/database/eximstats_db.sqlite3');
    but this errored stating 'Exception : could not find driver'. Again, I cannot see how I can call the sqlite3 binary in this code! So, I am still at a loss and after altering my script to try the three different methods of querying the database, it still doesn't work, mainly because I don't know how to implement the direct path method you recommend. Any thoughts? Thanks, Paddy
    0
  • cPanelMichael
    Hello @MrJingles, The /usr/local/cpanel/3rdparty/bin/sqlite3 binary is something you'd use directly from the command like or as part of a shell script. For instance, here's an example of a command you would use: /usr/local/cpanel/3rdparty/bin/sqlite3 /var/cpanel/eximstats_db.sqlite3 "SELECT * FROM failures"
    The binary is not applicable to your PHP or Perl scripts. Thank you.
    0
  • MrJingles
    Hi Michael, Thanks for the clarity. I can confirm that when I ran that line of code from the command it worked perfectly on the production server! Does this help in any way? Thanks for the support! Paddy
    0
  • cPanelMichael
    Hello @MrJingles, The command line method is an example of an alternative to developing a custom PHP or Perl application. You could simply develop a bash script that makes use of the /usr/local/cpanel/3rdparty/bin/sqlite3 binary. Thank you.
    0
  • MrJingles
    Hi Michael, It's been a while since you kindly got back to me, but I just wanted to provide an update in case anyone else wants to implement the solution I've used. My knowledge with bash scripts is limited but I decided that I would write one that basically created a csv file from the table and then called a php script to work with this csv file. The bash script basically stated two lines to run: #!/bin/bash /usr/local/cpanel/3rdparty/bin/sqlite3 -header -csv /var/cpanel/eximstats_db.sqlite3 "SELECT * FROM failures;" > /home/someone/temp/location/tostorecsvfiles/eximfailures.csv /usr/local/bin/php -f /location/to/php/script/script_to_process_failures.php
    I was then able to easily process the csv file and delete it from the server once completed in php which is my preferred programming language. Thanks again for such great help! Really superb and very much appreciated. Paddy
    0
  • cPanelMichael
    Hello Paddy, Thanks for sharing the solution!
    0
  • Sarangi Tech Solution
    hi
    0

Please sign in to leave a comment.