3

I am trying to connect to MYSQL database and cannot. I believe it has something to do with the PEAR error, and I"ve looked at this answer but it has been of no use.

Getting PEAR to work on XAMPP (Apache/MySQL stack on Windows)

My code is the following:

require 'DB.php';
require 'formhelpers.php';

$db = DB::connect('mysql://root:password@localhost/test');
if (DB::isError($db)) { die("connection error: " . $db->getMessage( )); }
$db->setErrorHandling(PEAR_ERROR_DIE);

//create table for responses 
$q = $db->query(
    "CREATE TABLE apiResponse(
    Name VARCHAR(20),
    Occupation VARCHAR(20)");

//select data to send
$db = DB::connect('mysql://root:password@localhost/test');
$q = $db->query('SELECT Name, Occupation FROM try2 ');
while ($row = $q->fetchRow())
{
$Name = $row[0];
$Occupation = $row[1];

$q = $db->query(
"INSERT INTO apiResponse (Name, Occupation) values ($Name, $Occupation)"
);

And I get the following errors:

Warning: require(formhelpers.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\myfiles\Testing API Script.php on line 10

Fatal error: require() [function.require]: Failed opening required 'formhelpers.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\myfiles\Testing API Script.php on line 10

Now, according to the other answer, this is a problem with finding PEAR. I have located the php.ini file and found the include statement. It is PHP's default setting for include_path is ".;/path/to/php/pear" which is what the answer suggested.

My questions:

  1. The file that needs to be corrected is the php.ini file in xamp? (I previously downloaded php straight from php.net)

  2. I have both a php.ini for development and for production... which one do I edit?

  3. The .ini file opens in notepad, I'm not sure this is the correct place to edit it. Confirmation?

Community
  • 1
  • 1
user1459268
  • 217
  • 1
  • 3
  • 9
  • line 10 is require 'formhelpers.php' – user1459268 Jun 22 '12 at 14:07
  • Then the formhelpers.php file can't be found - try finding the file, and adding an explicit, full path to the `require` line. – andrewsi Jun 22 '12 at 14:09
  • Just to be clear, you mean a full directory? i.e. C:\somethin\somethin\somethin\formhelpers.php – user1459268 Jun 22 '12 at 14:10
  • Yes - that way, the server can definitely find the file. – andrewsi Jun 22 '12 at 14:10
  • That didn't work. I downloaded formhelpers.php directly to my desktop just so I could find it easily for a test. I got the same sort of error. Warning: require(C:\Users\Clayton\Desktop\formhelpers.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\myfiles\Testing API Script.php on line 10 Fatal error: require() [function.require]: Failed opening required 'C:\Users\Clayton\Desktop\formhelpers.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\myfiles\Testing API Script.php on line 10. Any ideas? – user1459268 Jun 22 '12 at 14:15
  • I'd suggest it might be a permissions error, in that case - maybe your webserver software doesn't have rights to look in your c:\users\ directory? – andrewsi Jun 22 '12 at 14:27
  • same error, different directory... this time I put it in xamp, in the same place as the actual php file I'm running, so it must have access. – user1459268 Jun 22 '12 at 14:31
  • Could you try creating a new file in that same directory? It doesn't need to contain any content, but you should add a `require` line for it - see if the server can load that file. (Also, where is your DB.php file located? You could try copying formhelpers.php to that same directory, since loading that file doesn't seem to be an issue) – andrewsi Jun 22 '12 at 14:34

1 Answers1

0

You said that

It is PHP's default setting for include_path is ".;/path/to/php/pear" which is what the answer suggested.

You need to change that to the actual path to pear on your install. I use XAMPP under windows and have not trouble with this because I changed mine to .;\xampp\php\PEAR because that is where xampp default puts the installation of PEAR.

I also had to change a few things. See my answer in the Getting PEAR to work on XAMPP (Apache/MySQL stack on Windows) question for details on the pear config changes I had to make.

Community
  • 1
  • 1
Reid Johnson
  • 1,394
  • 14
  • 20