I am currently developing a PHP application that uses PDO. I am writing an import that reads in a CSV file, checks the database for writing and updates, deletes, etc.
Something I noticed is the memory used by this script seems very high, and it looks like it might be related to how I execute the request. see below for an example query that runs for each row in a CSV:
$qry = "SELECT * FROM company WHERE id = 1"; $sth = $this->prepare($qry); $sth->execute(); $sth->setFetchMode(PDO::FETCH_INTO, new Company()); $sth->fetch();
for the above memory_get_peak_usage () = 6291456
When using below:
$qry = "SELECT * FROM company WHERE id = 1"; $sth = $this->prepare($qry); $sth->execute(); $sth->setFetchMode(PDO::FETCH_CLASS, "Company"); $sth->fetch();
for the above memory_get_peak_usage () = 524288
As you can see, the difference is quite large.
I think I have 3 questions.
- Is there a memory leak when using PDO :: FETCH_OBJ in PHP 5.3.5?
- Is there a difference between using FETCH_CLASS as opposed to FETCH_OBJ?
- Has anyone else experienced the same issue?
The company class is simple:
class Company { function __construct(){} public $_tablename = 'company'; public $transient; public $id; public $name; }
source share