Jump to content

Recommended Posts

Hello all, i m doing this small piece of code to test out how can i get some data out of an mdb file, so i can peridicly check it and import new data into something easier to work with ... example MySQL. This script is to runned as a cron job, so i m running it using the php cli, this is the code i have so far:

<?php
        error_reporting(E_ALL);
        ini_set( 'display_errors', 1 );

        $mdbfile = "/var/www/html/db.mdb";

        if( file_exists( $mdbfile  ) ){
                try {
                        $dbh = new PDO("odbc:DRIVER={MsAccess};DSN=mdbtest;");
                        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                }catch (PDOException $e) {
                        echo $e->getMessage();
                }
        }else{
                die('File does not exist!');
        }

        foreach ( $dbh->query("SELECT * FROM MY_TABLE") as $row ){
                echo $row['Row1'];
        }

        if(isset($dbh)){
                $dbh = null;
        }
?>

when i run "php -f /var/www/html/php-pdo-odbc.php", i get the error "Segmentation fault", if i try to open the file from the web browser i get an error "The connection was reset". Commenting out some code i figured out that the error is in the foreach, but i dont see any issue with it .. could anyone give me an though why is this happening?

 

I m using CentOS 6.4 with Apache 2 and PHP5.5.6. Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/284097-segmentation-fault-issue/
Share on other sites

Segmentation faults are usually due to actual bugs in the underlying code or having a mix of different versions of php core files and extensions (i.e. not all built with the same c header files.)

 

is there any additional information in the web server's error log file?

 

you can check the php bug reports to see if anyone else is having the same problem and/or make a bug report if you feel this is something due to the underlying php code. (php 5.5.6 just fixed a segfault if the PDO constructor throws an exception, perhaps this is related to that.)

 

the only thing i can suggest you can try in the code would be to put a try/catch block around the foreach(){} block in case the query statement is failing and throwing an uncaught exception. temporarily turning off the PDO::ERRMODE_EXCEPTION may help pin point the issue (if its an actual bug in php.)

Hi thank you for your response, i did a couple of tests (including installing php 5.3.3) i get the same result as i described. I further found that mdbtools (the driver that was installed in the unixODBC) last version is from the year 2004, at this point i have no idea what to do ... thank you very much for your reply tho.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.