9three Posted April 27, 2010 Report Posted April 27, 2010 Hey, Now that I'm implementing namespaces, PDO is no longer being found. I'm doing: $this->db = new PDO('mysql:dbname=db;host=localhost', 'root', ''); It's trying to find application\path\PDO.php which is not the case. I tried doing: $this->db = new \PDO('mysql:dbname=db;host=localhost', 'root', ''); but that didn't work. The current namespace I'm using is: use \application\database as Mapper; Then I did: $this->db = new Mapper\PDO('mysql:dbname=db;host=localhost', 'root', ''); But that was no good either. It keeps looking for a physical file PDO.php. Not sure where I'm going wrong? Quote
grezman Posted July 7, 2010 Report Posted July 7, 2010 I had the same problem. But I overcame it by adding an alias namespace of PDO at the top of my class. i.e namespace my\folder; use PDO; class foo{ function zoo(){ $a = new \PDO(......); } } Quote
bishwadeep Posted July 8, 2010 Report Posted July 8, 2010 Hi This might help you. ob_start(); $db = new PDO('mysql:host=localhost;dbname=<SOMEDB>', '<USERNAME>', 'PASSWORD'); $stmt = $db->prepare("select contenttype, imagedata from images where id=?"); $stmt->execute(array($_GET['id'])); $stmt->bindColumn(1, $type, PDO::PARAM_STR, 256); $stmt->bindColumn(2, $lob, PDO::PARAM_LOB); $stmt->fetch(PDO::FETCH_BOUND); ob_clean(); header("Content-Type: $type"); echo $lob; // fpassthru reports an error that $lob is not a stream so echo is used in place. ob_end_flush(); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.