Solved

easiest test other than php.ini to test to see if pdo is working

Posted on 2011-09-18
10
437 Views
Last Modified: 2013-12-13
easiest test other than php.ini to test to see if pdo is working
0
Comment
Question by:rgb192
  • 5
  • 4
10 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 36558030
I normally write a small test page to get 10 rows or so like the sample below.  Change the details to your data and check your connections and info.  Once that is working then you can do more complicated things with some confidence.
<?php 
// DB configuration
$dbhost = "10.202.46.41";
$dbuser = "eecontact";
$dbpass = "easy4U";
$dbname = "nads";
$dbtable = "customercontact";
$dbdsn = "mysql:dbname=$dbname;host=$dbhost";

$dbh = new PDO($dbdsn, $dbuser, $dbpass);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>PDO dbCheck</title>
</head>
<body>
<?php 
echo "Host: $dbhost <br>";
?>
<table border="0" cellpadding="1" cellspacing="1" summary="local people" width="900px" bgcolor="#ffffff">
<caption><font style="font-weight: bold; font-size: 18pt; line-height: 24pt;">PDO::MySQL check</font></caption>
<tbody>
<tr bgcolor="#ffffff">
<th>id</th><th>name</th><th>phone</th><th>email</th><th>zip</th></tr>
<?php 
$wlsql = "SELECT * FROM $dbtable LIMIT 10";
$sth = $dbh->prepare($wlsql);
$sth->execute();

while ($row = $sth->fetch(PDO::FETCH_BOTH)) {
echo '<tr>';
echo '<td>'.$row['firstName'].'</td>';
echo '<td>'.$row['lastName'].'</td>';
echo '<td>'.$row['city'].'</td>';
echo '<td>'.$row['email'].'</td>';
echo '<td>'.$row['zip'].'</td>';
echo '</td></tr>';
}
?>
</tbody> 
</table>

</body>
</html>

Open in new window

0
 

Author Comment

by:rgb192
ID: 36558074
Fatal error: Class 'PDO' not found

so I think this means that pdo is not enabled on wamp

and I can not find pdo in php.ini even though I uncommented all the pdo lines
0
 
LVL 13

Expert Comment

by:dsmile
ID: 36558121
Create php file with this content <?php phpinfo();?>

See if you're using the right php.ini
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:rgb192
ID: 36558161
i am using correct php.ini
dave
code works using php ide (using a different php.ini)
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36558197
I just checked and it works fine in WAMP on my computer.  I enabled PDO using the tray icon for WAMP.  It's the only version of PHP I have on that computer.
0
 

Author Comment

by:rgb192
ID: 36563915
I followed your advice and enabled all the pdo using extensions on tray icon for wamp

I had to add these one at a time and after I added each, wamp restarted.

I still get same error.

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36564006
I assume that they show up in 'phpinfo()' on WAMP.  I don't know what to tell you at this point since the code is known to work on WAMP and on IIS on another computer.   Any chance the two versions of PHP are interfering with each other?
0
 

Author Comment

by:rgb192
ID: 36937586
one is for ide
other is for wamp

so I dont think there is interferance
0
 

Author Closing Comment

by:rgb192
ID: 37128945
this code sample did the trick
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37129220
Good, glad to help.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question