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
Share on other sites

I did not until you mentioned it...

 

Now i am getting an error that says

 

Warning: Invalid argument supplied for foreach() in /var/www/html/innovation/inno_show.php on line 72

 

And doing some searching means my query is wrong... but i don't see how it is.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.