[PHP-DB] supporting multiple databases...

2005-01-30 Thread Paul Chvostek
Hiya.

I'm writing an application which needs to make SQL queries, and I'd like
to give it support for multiple database servers, starting with MySQL
and PostgreSQL.  I see that other folks have done this with a variety of
methods, and I can't see a clear winner.

Option 1 - Drop in a set of db-related functions as part of the install
procedure.  I.e. a file db_func.php is copied from db_func.php-pg or
db_func.php-my as part of the install procedure.  The functions
contained will return equivalent results.  This has the advantage of
leaving the installed application more streamlined, but it requires
better coordination between functions and things that call them; your
total number of db functions is multiplied by the number of databases
supported.

Option 2 - Select function behaviour based on a config variable.  That
is, the same database functions will run, but there can be if() or
switch() statements to control how the db is dealt with.  This keeps the
function list tighter, but it seems to make for less elegant and
probably less maintainable code.

Option 3 - Write relatively generic database functions, but control the
format of SELECTs and even the db connect functions called from config
variables.  This seems elegant on the surface, but make for highly
obtuse code.

Is there a preferred method of handling this issue, or does everybody
just roll their own?

-- 
  Paul Chvostek [EMAIL PROTECTED]
  it.canadahttp://www.it.ca/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Database question

2003-07-03 Thread Paul Chvostek
On Thu, Jul 03, 2003 at 07:00:17AM -0700, Hardik Doshi wrote:

 Currently i am connecting the underlying database
 server from every php page. To reduce the connection
 overhead i am thinking to store the PEAR DB object
 into the registry (session) at the time of user login.
 Here i am connecting the Database only one time and
 rest of the time i am using the object stored in the
 memory.

Nice as it sounds, this won't work.  I don't recall where it's
documented, but at least with MySQL (and I'm assuming with the others as
well), a database link identifier cannot be stored in a session variable
and then re-used by another session.  Check out
http://www.php.net/features.persistent-connections for details.

-- 
  Paul Chvostek [EMAIL PROTECTED]
  it.canadahttp://www.it.ca/
  Free PHP web hosting!http://www.it.ca/web/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Making a text wrapper

2003-02-22 Thread Paul Chvostek
On Sun, Feb 23, 2003 at 01:53:55AM +0100, Lars Rasmussen wrote:

 I'm had to make a text wrapper that can take a string, and count the
 letters in words (and spaces) and exaple make a br each time 64
 caracters has passed (BUT it may NOT split words into two...)

If http://www.php.net/wordwrap doesn't do what you need, and the extra
comments on that page don't provide additional resources that are useful
for you, then perhaps you can provide more details on the php-general
list, where this will be a little more on topic.

-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever
  it.canada, hosting and development   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Is my Hosting service full of it?

2003-02-09 Thread Paul Chvostek
On Sat, Feb 08, 2003 at 01:13:28PM -0500, pthes wrote:
 
 Here are some claims from the hosting service:
...
 It is exceptionally PHP and MySQL heavy and unfortunately not the kind of
 application you can safely run in a shared-hosting environment.

It is never safe to allow customers to upload their own scripts in a
shared hosting environment.  I can't count the number of times I've had
to step in and disable an account (or at least a CGI) because a customer
wrote or uploaded something that consumed too many resources.

 So you suggest leaving the db open? What happens when someone bails out
 before the end? Would that then cause another problem?
 
 - You should be able to initiate a db close after a certain amount of time.

Without seeing the code, it's hard to determine what you're doing wrong;
if you're using a CREATE TEMPORARY TABLE, the table will automatically
be deleted shortly after the database connection is closed.  This would
obviously consume memory in the database server for every temporary
table created.

 Are concurrent connects with mysql the problem?
 
 - They certainly don't help. The MySQL server is shared amongst other sites
 on this same server and obviously can only handle so much happening at once.

If you're using mysql_pconnect() to talk to the server, remember that
each persistent connection is tied to just one web server process.  If
the web server has MaxClients 150 set, then there can be a maximum of
150 persistent database connections, even if there's just one PHP script
opening them all.

 Comment 5: response to I don't believe php is worse than perl
 CGI scripts are called once a form has been completed, the script then runs
 quickly and closes itself. A pHp page May open a connection to mySQL at the
 opening of the page, or later in it: either way instead of having the
 information passed to mysql in a separate place, it is done in the same
 place.
 
 It gives the impression of being more efficient(since a step is skipped) but
 for high traffic operations it can bog down a mySQL server, Especially if it
 is a shared one.

This is legitimate.  I've seen serious degradation of MySQL performance
with much lower load than you're generating, always caused by
programming with a complete lack of regard for the database server's
resource limits.  If you don't know how to make your code more database
friendly, you might want to consider hiring a programmer to do it for
you.  Or if you prefer, spend the money on a dedicated server, and watch
*it* grind to a halt as well.  :)

 I wondering if anyone has an opinion of whether I'm dealing with people who
 don't know what they're doing. Do any of their comments make sense.
 I'd be glad to provide further clarification if desired. I just have a real
 feeling that I'm not getting knowledgable answers.

You are, they do, and you are.

-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever
  it.canada, hosting and development   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] elseif

2003-01-27 Thread Paul Chvostek
On Mon, Jan 27, 2003 at 06:26:06PM -0600, Addison Ellis wrote:
 
 hello and thank you for your time.
   will the below work to check if one field or the other is 
 filled in upon submission? either contact_phone or contact_email is 
 required but not both. best, addison

I would use something like:

$error = ;
if (strlen(trim($name))  1) {
$error .= liYou must enter a company name.\n;
}
...
if (! ($contact_phone || $contact_email) ) {
$error .= liYou must enter a contact phone number or email address.\n;
}
if (strlen(trim($contact_email))  0  
eregi('[a-z0-9_.-]+@([a-z0-9]+\.)+[a-z][a-z]+',$contact_email)) {
$error .= liEmail address has an invalid format.\n;
}
if (!$error) {
$q = INSERT INTO stores blah blah;
...
}

 $error = ;
 if ($name == )
   {
   $error = $errorLIYou must enter a company name./LI;
   }
 if ($address == )
  {
  $error = $errorLIYou must enter an address./LI;
  }
 if ($city == )
  {
  $error = $errorLIYou must enter a city./LI;
  }
 if ($state == )
  {
  $error = $errorLIYou must enter a state./LI;
  }
 if ($zip == )
  {
  $error = $errorLIYou must enter a zip./LI;
  }
 if ($contact_phone == )
  {
  $error = $errorLIYou must enter a contact phone number or 
 email address./LI;
  }
 elseif ($contact_email == )
  {
  $error = $errorLIYou must enter a contact phone number or 
 email address./LI;
  }
 if ($error == )
   {
   $query = insert into stores  set
 -- 
 Addison Ellis
 small independent publishing co.
 114 B 29th Avenue North
 Nashville, TN 37203
 (615) 321-1791
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 subsidiaries of small independent publishing co.
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever
  it.canada, hosting and development   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] dates and updates recommendation?

2003-01-26 Thread Paul Chvostek

Hiya.

I'm looking for some design advice.

I have a number of tables whose data consist of configuration details
and parameters that are incorporated into config files for various
server applications.  For example, a table of customers' email address
forwarding info, so a PHP application can be used to add/modify/remove
email forwarding in a MySQL table, and a small script is used to build a
fresh sendmail virtusertable whenever there are updates to the table.

Each of the tables contains data that reflect configuration of the
servers (POP3 mailboxes, FTP users, Apache module directives, etc).
Each table has a field called changed which gets updated with the
current date/time every time the data is changed.  Due to lack of
planning, some tables store dates as DATETIME, and others store it as
an unsigned INT containing the epoch second.  I want to standardize
on one or the other, and I don't know which direction to go.

So what's the best way to store a date?  I've always liked storing epoch
seconds as INTs, and leaving the translation to/from a human-readable
date up to the application, but aside from the relative unreadability of
this, are there any significant disadvantages to this method, aside from
the rollover problem in 2038?  (The S32b bug?)

Would I be better off spending a few bytes extra per record and storing
things as DATETIME rather than an INT?  If I'm looking at the possibily
making the application more database-portable in the future, are there
gotchas I should be aware of with any particular field types?

Thanks.  :)

-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever
  it.canada, hosting and development   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] Find and replace in a string

2003-01-26 Thread Paul Chvostek
On Mon, Jan 27, 2003 at 12:57:10AM +0200, Nikos Gatsis wrote:

 Hi list!
 I have a sting that contains some occurances of {...} sub-strings, where  is 
some text.
 Which is the way to find and replace the {...} with an other of my own.
 This sub-strings start with { and end with }.

You could try something with a regular expression like:

$new = ereg('[^{]*{([^}]*)}.*', '\\1', $oldstring);

which will match only the first word inside curly braces, or if
$oldstring contains multiple strings in curly braces, maybe:

$newarray = split('}?[^{]*{', $oldstring . '{');

and then parse the array, and you'll probably want to toss [0], as it
will contain the data before the first left-curly-brace.  This method
needs a trailing left-curly-brace appended to $oldstring because the
regexp relies on it to mark the field.  You could alternately turn this
around as:

$newarray = split('}[^{]*{?', '}' . $oldstring);

which is probably the cleanest way to do this, given the extent to which
you've described the data so far.  Note that split() will work just fine
on multi-line arrays, including fields split over multiple lines.  If
you want to process your data line-by-line, you'd need to wrap it.

The better you can predict the input data, the cleaner the code you can
use to parse it.

Learn the regexps.

-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever
  it.canada, hosting and development   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Serve images from files, or db?

2002-12-31 Thread Paul Chvostek

Assuming an image isn't necessarily graphical (i.e. it could be a
downloadable file of any type), what are the considerations with regard
to serving binary data out of BLOBs versus recording filenames or URLs
in a table and serving them up by reference?

I've got two slightly different projects that will need to do this.  The
first is a software download site whose users buy access that lets them
download a single file.  There will probably be only 40 or 50 files in
the collection, updated every few weeks.  Users will log in multiple
times to get updates to the files to which they've got subscriptions.

The second project has to provide more complex fraud screening -- i.e.
stop a file from being downloaded by the same user account from too many
different IP addresses in a given time -- but every user has equal
access to all the files in the collection.

What should I be considering when coming up with a strategy for these
two projects?  What are the strengths and weaknesses of storing files
in a BLOB versus storing pointers to those files?

Thanks.  :)

-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever  
  it.canada, hosting and development   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php