Basic text not displaying

Hi,

Glad the upgrade went ok!

I ran your code and did not get errors although your not using the prepare statement properly so not escaping any data. I have included this in the code below. Please check to see that your column and table names are correct and that you call the GetSchedule() function correctly.:


<?php
$o_Db = DbFactory::getFactory()->getConnection();
echo 'PDO Db: ' ; echo var_dump($o_Db) . '<br />';
$table_name = 'users';
$fields = array(' uid_number ', ' uid ');
$data = GetSchedule($o_Db, $table_name, $fields);
echo 'Data: '; echo var_dump($data) . '<br />';

function GetSchedule(PDO $o_Db, $table_name, $fields){
  if(!$o_Db || !$table_name || !fields){
    throw new exception('GetData(PDO $o_Db, string $table_name, array or string $fields. You did not pass one of the variables');
  }
  if(is_array($fields)){
    $sql_fields = array();
    $binds = array();
    foreach($fields as $value){
        $sql_fields[] = "?";
        $binds[] = $value;
    }
  }
  /*
  *implode the $sql_fields names, separating with a comma using join()
  */
  $sql = 'SELECT ' . join(', ', $sql_fields) . ' FROM ?';
  $stmt = $o_Db->prepare($sql);
  $i = 0;
  foreach($binds as $bind){
    $stmt->bindValue(++$i, $bind);
  }
  /*
  * Table name is last parameter so count the total number of fields
  * and then add one to equal the parameter position for table_name
  */
  $table_p = count($binds) + 1;
  $stmt->bindParam($table_p, $table_name);
  $stmt->execute();
  return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
  }
?>

var_dump($o_Db); gives

object(PDO)#2 (0)

and

var_dump($data); gives me rows from my test database

Steve

Unfortunately, the new code multiplied the errors by three. The var_dump($o_Db); just duplicated one error and var_dump($data); did not produce anything.

I did add data directly to the tables via PHPMyAdmin and that is showing up as it should on the site. However, these errors are also showing within the pages’ content.

The original script is being used here: http://www.sullychristian.org/about/board.php
New version can be found here: http://www.sullychristian.org/about/committees.php

If you go to the links, you’ll see what I mean for multiple errors.

Hi vmtech,

If you are getting an error with var_dump($o_Db); then your PDO object is not getting created; therefore all other errors will be a result of having no db connection to work with.

You need to troubleshoot why the PDO object is not created. You need to ensure that your connection string to the database is correct. Is the database named the same thing? Is the db username the same? Most hosts don’t let you use a root account (unless this is a self managed VPS) so you won’t be able to use root.

If none of that helps, then simplify the creation of the PDO object and in a test page just try var_dumping

$db = new PDO("mysql:host=216.51.232.202;dbname=db1569", "user", "password"); 

[COLOR=#000000]see if you get a connection. If not then you know it is something to do with your connection string.

Looking at your site won’t help, as these things are generated server side; your above code was the most helpful.

Regards,
Steve[/COLOR]

I only suggested visiting the pages because the errors are being printed directly on the page. No, you can’t see the PHP code behind it, but just seeing the errors it produces.

The test page worked with object(PDO)#1 (0) { } given as the result. One area of the page is showing data from the database exactly as it’s supposed to, but without listing the error strings as well.

Sorry to bump this, but I’m still in need of help. I have exhausted my resources outside of Sitepoint and don’t know where else to look. Thanks for all your help already, it has been greatly appreciated.