Jump to content

Recommended Posts

Posted

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?

  • 2 months later...
Posted

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(......);

 

}

 

}

Posted

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();

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...