Solved

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

Posted on 2011-09-18
10
434 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

803 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