Jump to content

Recommended Posts

Posted

Has anyone used the PEAR Database package to access their mysql database on TCH? I'm told these packages are installed....If you have can you give me an example of your $dsn and how you include the db.php file? (If this is even possible????)

 

Thanks,

 

JM

Posted

Pear is:

 

PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit

 

you can get more info at:

 

pear.php.net

Posted

Ok, I just used it. It's easy. Here's what I did.

 

I use a config file (called dbinfo.php) to hold all of my variables, which looks like this....

><?php

$dbhost = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbname = 'bohican_test';

$gametable = "games";     //name of table to be accessed

?>

 

I then access that using the following PEAR code....

><?php

   include('dbinfo.php');
   require_once( 'DB.php' );
   $db = DB::connect( "mysql://$dbuser:$dbpass@$dbhost/$dbname" );
   $sql = 'SELECT * FROM '.$gametable;
   $result = $db->query($sql);
   while ($row = $result->fetchRow()) {
       echo $row[2] . '<br>';
   }
   $db->disconnect();

?>  

Of course, I should comment some of that, but it's just a test. :) If anyone doesn't know what the heck is going on in any of that code, just hollar and I'll go through and comment it to death. :(

 

btw, "require_once( 'DB.php' );" includes the pear file. Don't worry about where it really is, just include that line and you should be fine.

  • 9 months later...
Posted
btw, "require_once( 'DB.php' );" includes the pear file.  Don't worry about where it really is, just include that line and you should be fine.

hi,

 

i'm testing out some sample code that uses the PEAR module and i'm having trouble with this. the file has "require_once("DB.php")" but for some reason it can't find it. are you sure i don't need to set the include_path? i'm on server35 if that makes any difference. my error message is as follows (am i understanding it incorrectly?):

 

Warning: main(DB.php): failed to open stream: No such file or directory in /home/mysite/public_html/test/_lib/_classes/class.ads.php on line 5

 

Fatal error: main(): Failed opening required 'DB.php' (include_path='.:/home/mysite/public_html/test/core:/home/mysite/public_html/test/site:/home/mysite/public_html/test/_lib/_base:/home/mysite/public_html/test/_lib/_classes') in /home/mysite/public_html/test/_lib/_classes/class.ads.php on line 5

 

thanks for you help!

Posted (edited)

That require_once statement should work just fine, perhaps it's something wrong with server35. Please open a help desk ticket so one of the techs can take a look at the problem.

 

Edit: Scratch what I just said. I can see that your include path does not include any usual PHP include paths, only paths to subdirectories in your home directory, which leads me to think that you're setting the include_path yourself, am I right?

 

That's probably the source of your problem: you're overwriting PHP's include_path. Try fetching the current include_path first and then adding to that, like this:

 

$include_path = ini_get("include_path");

$include_path .= ".:/home/mysite/public_html/test/core:/home/mysite/public_html/test/site:/home/mysite/public_html/test/_lib/_base:/home/mysite/public_html/test/_lib/_classes";

ini_set("include_path", $include_path);

Edited by TCH-Raul
Posted

thanks, raul! you nailed it.

 

$include_path = ini_get("include_path");

$include_path .= ".:/home/mysite/public_html/test/core:/home/mysite/public_html/test/site:/home/mysite/public_html/test/_lib/_base:/home/mysite/public_html/test/_lib/_classes";

ini_set("include_path", $include_path);

 

if i'm not mistaken, ini_set only changes my settings for the duration of the script, right? if i want to set my include path for all scripts, could i use the .htaccess file? how do i do it there? right now, i'm simply using this:

 

>php_value include_path '.:/home/mysite/public_html/test/core:/home/mysite/public_html/test/site:/home/mysite/public_html/test/_lib/_base:/home/mysite/public_html/test/_lib/_classes'

 

i'm a newbie at editing .htaccess files so you'll have to excuse me :dance: is there a way i can put the current include_path into my new definition? something like this:

 

>php_value include_path '$include_path:/home/new/path'

 

this exact syntax doesn't work of course. how do i reference variables in .htaccess? is there a better way? the book i got the sample code from used something similar.

 

thanks for your help! :P

Posted (edited)

Yes, ini_set will only change that configuration setting for the duration of the script.

 

I'm not sure if you can reference PHP's include_path in a .htaccess file but I'll check it out.

 

In the meanwhile, why don't you simply create a file called, for instance, "include_paths.php" with the following content

><?php
$include_path = ini_get("include_path");
$include_path .= ".:/home/mysite/public_html/test/core:/home/mysite/public_html/test/site:/home/mysite/public_html/test/_lib/_base:/home/mysite/public_html/test/_lib/_classes";
ini_set("include_path", $include_path);
?>

and include("include_paths.php") it in every PHP script that needs access to the include path? :rolleyes:

Edited by TCH-Raul
Posted

thanks for the suggestion. do let me know if you figure out the .htaccess problem though. i'm always happy to learn new things. i scoured the net and i can't seem to find an example where you're appending to the include_path instead of redefining it.

 

by the way, do you have any idea what, if any, performance difference there is between using the .htaccess method as opposed to creating a common include? does one way scale better than the other? just curious.

 

again, thanks for your help!

Posted

To reference PHP_Include in .htaccess try either of these

 

phpvalue include_path path/to/your/includes

 

php_value include_path ".:/path/to/your/includes"

 

and let me know if it works.

Posted
php_value include_path ".:/path/to/your/includes"

that's what i already have and it doesn't work. include_path is getting replaced with what's in the double quotes. what i'd like is a way to append the current include_path with what's in the quotes, so as to preserver the include_path set by you guys at TCH. thanks though.

Posted

Sorry, I didnt read it completely and only saw

 

php_value include_path '$include_path:/home/new/path'

 

I will keep looking

 

Did you try the first one? Long shot but I have seen it before.

Posted

no worries :rolleyes: i'm starting to think it's not possible now.. i guess i'll have to set the include path all the time like raul mentioned

Posted
Another dumb ?  I see it as ".:" and ".;"  have you tried ".;" yet?

looks like that doesn't help.

Posted (edited)

Rob, the difference between ".:" and ".;" is that the first is the Unix syntax and the second is the Windows syntax :D

 

As for using the current include_path in .htaccess, I'm convinced it is not possible. It is possible to set it, as we have seen in lots of examples, but I haven't been able to find one single reference about how to refer to PHP's include_path from within a .htaccess file so that it can be appended to instead of replaced :(

 

About the performance question, the quick answer is: there's no difference :)

 

There may be a little tiny winy bit more processing needed by the common include method, because it's a PHP file and it needs to be processed by PHP but on the other hand, .htaccess also has to be parsed by Apache but even so, it's reallt not important. I don't even think it's noticeable, so don't worry about it :)

Edited by TCH-Raul

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...