Jump to content

Php.ini and PDO help.


Bladescope

Recommended Posts

Right, starting off, hey and good evening for me. Sorry for what seems like a demanding first post, but any help on this would be greatly appreciated.

 

I'm running php 5.2 on a home server (appserv) and i've been looking into starting to use Php Data Objects with MySQL.

Now, when i've tried testing it (using a basic try/connect script) it's generated the error that the PDO class doesn't exist, so I tried the script on my webspace and it worked perfectly, so from what I gathered, it must be something to do with my server's php files.

So, opened up my php.ini, and found that the 3 files weren't enabled (and the extension path wasn't set).

So, in php.ini, the file now has these lines in it:

 

extension_dir = "./ext"

 

extension=php_mysql.dll

extension=php_pdo.dll

extension=php_pdo_mysql.dll

 

running php.exe from there, generated no errors about missing files, so i've assumed that it has managed to find the files, or that it just hasn't checked for them, but when I came back to run the same script, it generated the same error which is that the class PDO is non-existant.

 

I've tried restarting my computer and nothing has changed, so i'm asking for a little bit of help as to what else I may need to do to enable PDO for my home server.

 

Here's the code I use:

<?php
try {
   $dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'mypasswordgoeshere');
   foreach ($dbh->query('SELECT * from FOO') as $row) {
      print_r($row);
   }
   $dbh = null;
} catch (PDOException $e) {
   print "Error!: " . $e->getMessage() . "<br/>";
   die();
}
?>

 

Generates

 

Fatal error: Class 'PDO' not found in C:\AppServ\www\pdo.php on line 3

 

The extensions are located at: C:\Appserv\php5\ext

The php.ini file is located at: C:\Appserv\php5\php.ini

 

Any help at all would be great, and i'll provide more info if you need it.

 

Thanks in advance,

Sean.

Link to comment
Share on other sites

Always set the extension_dir with an absolute path:

extension_dir = "C:/Appserv/php5/ext"

 

also in order for php to display errors if it is having issues loading extensions during startup you'll need to enable the display_startup_error setting in the php.ini too.

Save the php.ini and restart Appserv

Link to comment
Share on other sites

Oh darn.

 

I should've thought as much.

 

Let me explain:

 

PHP Version 5.2.3

 

System Windows NT SEAN 5.1 build 2600

Build Date May 31 2007 09:36:39

Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"

Server API Apache 2.0 Handler

Virtual Directory Support enabled

Configuration File (php.ini) Path C:\WINDOWS

Loaded Configuration File C:\WINDOWS\php.ini

PHP API 20041225

PHP Extension 20060613

Zend Extension 220060519

Debug Build no

Thread Safety enabled

Zend Memory Manager enabled

IPv6 Support enabled

Registered PHP Streams php, file, data, http, ftp, compress.zlib

Registered Stream Socket Transports tcp, udp

Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.*

 

the question remains, do I need to put my php.ini file in the WINDOWS directory, or is there some way to change the path. (Thanks for the help so far, helped a lot)

Link to comment
Share on other sites

PHP is currently reading a php.ini in C:\WINDOWS\ if you are editing the php.ini in C:\Appserv\php5 either delete the current php.ini in C:\WINDOWS or overwrite it with the one in C:\Appserv\php5

 

Make sure your restart Appserv after moving the php.ini

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.