Solved

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

Posted on 2011-09-18
10
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

623 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