Solved

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

Posted on 2011-09-18
10
431 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 82

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
 

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 82

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 82

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 82

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now