PHPBuilder - PHPLib and Multiple Databases Page 6



RSS Twitter
Articles Databases

PHPLib and Multiple Databases - Page 6

by: Peter Moulding
|
November 7, 2000

PHPLIB writes cookies. A print statement in the middle of PHPLIB may produce error messages about problems writing HTTP headers. Ignore the errors or write the diagnostic messages to a disk file. Start with:
 $db_log_file = "t:/diag.txt";
...or similar. Point to a text file somewhere on your disk. In Windows, make sure you use a directory that exists or you will get a weird error.
Now define:

<?php

function db_log($db_log_message) {
    
globals $db_log_file;
    
$db_log_f fopen($db_log_file"a");
    
fwrite($db_log_fdate("Y m d H:i:s")." ".$db_log_message."\r\n");
    
fclose($db_log_f);
}

?>
Anytime you need to see what is happening, add log messages like:

<?php

db_log
("current database: " db_database());

?>
There are some built in logging techniques and system logs you can use. You may not have access to the right directories and may have to search large files to find a tiny piece of information. This separate log gives you some control during testing. I recommend it before and after logs like:

<?php

db_log
("current database: " db_database());
db_database("bookcatalogue");
db_log("current database: " db_database());

?>
Remember to use the right database in your database accesses so you do not query the PHPLIB database. You might like to create a wrapper function for the database query function or change the function you use. If you use mysql_query(), you can use db_database() first. You can also replace:

<?php

db_database
("bookcatalogue");
$result mysql_query("select * from?"db_connect());

?>
with

<?php

$result 
mysql_db_query(db_database("bookcatalogue"), "select * from?",
db_connect());

?>
which suggests the function:

<?php

function db_query($db_query_database$db_query_sql) {
    return(
mysql_db_query(db_database($db_query_database), $db_query_sql,
    
db_connect());
}

?>
Now you can
  • use PHPLIB (and any similar software) with multiple databases
  • extend classes/objects
  • insert diagnostic checks
  • write a log of anything to a file
Practice them in reverse order. Get the log file working, then the diagnostic check, then one class extension and then go wild.
Happy coding!
-- Peter

« Previous Page
1
|
2
|
3
|
4
|
5
|
6

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Peter Moulding

Comment:



Comment:

(Maximum characters: 1200). You have characters left.