jmather Posted October 14, 2003 Posted October 14, 2003 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 Quote
DarqFlare Posted October 14, 2003 Posted October 14, 2003 PEAR DB? Haven't ventured out there yet... Quote
vendlus Posted October 14, 2003 Posted October 14, 2003 I don't think I've ever heard of the PEAR package.... what is it?? Quote
jmather Posted October 14, 2003 Author Posted October 14, 2003 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 Quote
vendlus Posted October 14, 2003 Posted October 14, 2003 ooh... I like it... I'm off to play with it.... I'll be back later... or sooner if I get frustrated Quote
vendlus Posted October 14, 2003 Posted October 14, 2003 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. Quote
jmather Posted October 15, 2003 Author Posted October 15, 2003 Looks great....thanks for taking the time to try that out. Quote
vendlus Posted October 15, 2003 Posted October 15, 2003 No prob. The connect string is kind of weird, but I guess that's not a big deal since it's all variables and I'd never have to actually remember it. Quote
kktran Posted August 11, 2004 Posted August 11, 2004 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! Quote
borfast Posted August 11, 2004 Posted August 11, 2004 (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 August 11, 2004 by TCH-Raul Quote
kktran Posted August 11, 2004 Posted August 11, 2004 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 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! Quote
borfast Posted August 11, 2004 Posted August 11, 2004 (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? Edited August 11, 2004 by TCH-Raul Quote
kktran Posted August 11, 2004 Posted August 11, 2004 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! Quote
TCH-Rob Posted August 12, 2004 Posted August 12, 2004 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. Quote
kktran Posted August 12, 2004 Posted August 12, 2004 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. Quote
TCH-Rob Posted August 12, 2004 Posted August 12, 2004 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. Quote
kktran Posted August 12, 2004 Posted August 12, 2004 no worries 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 Quote
TCH-Rob Posted August 12, 2004 Posted August 12, 2004 Another dumb ? I see it as ".:" and ".;" have you tried ".;" yet? Quote
kktran Posted August 12, 2004 Posted August 12, 2004 Another dumb ? I see it as ".:" and ".;" have you tried ".;" yet? looks like that doesn't help. Quote
borfast Posted August 12, 2004 Posted August 12, 2004 (edited) Rob, the difference between ".:" and ".;" is that the first is the Unix syntax and the second is the Windows syntax 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 August 12, 2004 by TCH-Raul Quote
kktran Posted August 12, 2004 Posted August 12, 2004 thanks for your help, guys! much appreciated. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.