troubleshooting Question

Warning: PDOStatement::fetch() expects parameter 2 to be long, string

Avatar of rgb192
rgb192Flag for United States of America asked on
PHP
22 Comments4 Solutions5085 ViewsLast Modified:
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
final example of fetch is generating this warning and no output
Warning: PDOStatement::fetch() expects parameter 2 to be long, string given in C:\wamp\www\oop-beg\pdo9.php on line 30

<?php
class secret_person{
  public $name;
  public $addr;
  public $city;
  public $other_data;
  
  function __construct($other=''){
    $this->addr=preg_replace('/[a-z]/','x',$this->addr);
    $this->other_data=$other;
  }
}

# connect to the database
try{
  $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);  
  $DBH->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  #using the shortcut->query() method here since there is no variable
  #values in the select statement.
  $STH=$DBH->query('SELECT name,addr,city from test');
  #setting the fetch mode
  //$STH->setFetchMode(PDO::FETCH_CLASS | 'secret_person',array('stuff'));
  echo '<br>';
  $i=0;
  while($rowObj=$STH->fetch(PDO::FETCH_CLASS,'secret_person',array($i))){
    //echo $obj->name.'<br>';
    echo $obj->addr.'<br>';
    //echo $obj->city.'<br>';
  }
  
}
catch(PDOException $e){
  echo '<br>no results';
  echo '<br>$e:'.$e;
  echo '<br>$e->getMessage():'.$e->getMessage();
  file_put_contents('PDOErrors.txt',$e->getMessage(),FILE_APPEND);
}
$DBH=null;
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 4 Answers and 22 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros