Fixing PHP PEAR error

2019-02-26 01:40发布

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?

1条回答
女痞
2楼-- · 2019-02-26 02:18

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.

查看更多
登录 后发表回答