Jump to content

PDO issues.


synking

Recommended Posts

Hey guys hope you can help.  I'm learning to use pdo and just started but for some reason what i am trying does not work.  here is the code

 

try{

   $dbh = new PDO("mysql:host=$serv;dbname=$data", $name, $pass);
   $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );


  $sql = 'Select * from Customer_Card';

  $sth = $dbh->prepare($sql);

  $sth->execute();

$tables = '';
foreach ($sth->fetch(PDO::FETCH_ASSOC) as $row) {
         echo "<pre>";
         print($row);
         echo "</pre>";
         $tables .= " <tr>";
         $tables .= " <td>{$row['Name']}        </td>\n";
         $tables .= " <td>{$row['Headline']}    </td>\n";
         $tables .= " <td>{$row['Problem']}     </td>\n";
         $tables .= " <td>{$row['Promise']}     </td>\n";
         $tables .= " <td>{$row['Proof']}       </td>\n";
         $tables .= " <td>{$row['Threats']}     </td>\n";
         $tables .= " <td>{$row['Passion']}    </td>\n";
         $tables .= " <td>{$row['Cost']}    </td>\n";
         $tables .= " <td>{$row['Value']}    </td>\n";
         $tables .= " <td>{$row['Purpose']}    </td>\n";


} }

catch(PDOException $e) {
    echo ("I'm sorry, Dave. I'm aftraid I can't do that.");
    error_log($e-getMessage());
}

 

Im not sure what im doing wrong but i get no errors and no data from mysql.

Link to comment
https://forums.phpfreaks.com/topic/267065-pdo-issues/
Share on other sites

Yes it is i just loged into mysql and checked everything with the credintials and everything.  Unless PDO does not like localhost as a server name.  Thats the only thing i can think of..  Does PDO prefer a type of server over another.

 

I even changed the connection to

 

try{

   $dbh = new PDO("mysql:host=localhost;dbname=innovation", 'inno', 'inno');
   $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

 

But still no rows returned  I am confused by this.

Link to comment
https://forums.phpfreaks.com/topic/267065-pdo-issues/#findComment-1369364
Share on other sites

Actually just found out what was wrong... When i logged in as the user that is allowed to access just that database nothing happens... when i looged in as root it was reporting the database is curropt... does pdo not see that...

 

either way it works now that i repeaired the database.

 

Sorry for all the issues.

Link to comment
https://forums.phpfreaks.com/topic/267065-pdo-issues/#findComment-1369366
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.