php-general Digest 3 Jul 2006 12:37:22 -0000 Issue 4219

Topics (messages 239075 through 239087):

Re: global class instance
        239075 by: Chris

Re: Update or add?
        239076 by: Chris

Re: ONE PAGE CONNECTS MANY DATABASE
        239077 by: Chris

Problems installing 5.1.4
        239078 by: Ashley M. Kirchner

Re: Programming question - New to PHP
        239079 by: Russbucket

Re: Templates, PHP Frameworks, and DB Abstraction?
        239080 by: Manuel Lemos
        239082 by: Lester Caine
        239085 by: Kevin Waterson
        239086 by: Lester Caine
        239087 by: Jens Kleikamp

Re: Update site through email
        239081 by: Manuel Lemos

Printing in php
        239083 by: weetat
        239084 by: Chris

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
sempsteen wrote:
yes i'm calling a lot. actually i have a class that handles mysql
queries named "database".
what i want was call a database method from a method of another function.

class
....
  function
  ...$database->execute_query(...

Always CC the list.

What's wrong with this being a global variable?

In your common or global or whatever you call it file:

$db = &new Db();
$db->Connect('....');
$GLOBALS['Database'] = &$db;

then you use $GLOBALS['Database']->...

This file is *always* called before your other classes so it's always set. It can't be overridden or anything, so I don't understand the objection to it being a global variable.


Another option, inside your main class (you're using inheritance right?)

var $Db = null;

function GetDb() {
  if (!is_null($this->Db) && is_resource($this->Db->Connection)) {
    return $this->Db;
  }
  $db = & new Db();
  $db->Connect(...);
  $this->Db = &$db;
}

then use

$db = $this->GetDb();

inside your class.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Brian Dunning wrote:
I have a table where I want to update each record with today's date as it's hit, or add the record if it's not in there:

+------+-----------------+------------+
|  id  |  creation_date  |  last_hit  |
+------+-----------------+------------+

I'm trying to do this with a minimum of hits to the db, so rather than first searching to see if a matching record is in there, I thought I'd just go ahead and update the matching record, check to see if it failed, and if it failed then add a new one, like this:

$id = $_GET['id'];
// Update
$query = "update table set last_hit=NOW() where id='$id'";
$result = mysql_query($query);
// Add
if(the update failed) {
$query = "insert into table (id,creation_date,last_hit) values ('$id',NOW(),NOW())";
  $result = mysql_query($query);
}

What's the fastest way to check if the update failed?

You have a few options as others have pointed out, but I'll post this as an option anyway.


Other db's don't have replace into or the "on duplicate key" option either, so you'd need to do something like this:

$query = "update ..";
$result = mysql_query($query);
if (mysql_affected_rows($result) == 0) {
// do the insert.
}


--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
BBC wrote:
Yes I'm using MySQL and the DataBases I mean are in different servers but the problem is I don't know how to set the host.
All input will be very helpful...

Maybe this was an accidental duplicate post, but you've done this with a few of your questions.

Sending the same question over and over again isn't going to get you a different response.

If you don't understand one of the (many) replies you receive, then tell us what part you don't understand and ask us to explain it further.

http://php.net/mysql_connect explains how to set the different hosts (servers) when connecting to the database.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---

I'm trying to get v5.1.4 installed on my server and running into something of a mystery. I can configure and run make with no problem. When I run 'make install' however, it starts the process, installing the dynamic modules, PHP SAPI module, make the necessary changes in httpd.conf and moves on to installing the other pieces:

--------------------
Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/share/man/man1/
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20050922/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
 program: phpize
 program: php-config
Installing man pages:             /usr/share/man/man1/
 page: phpize.1
 page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
--------------------

That's where it just dies. Dies in the sense that, it just sits there. Doesn't seem to be doing anything at all. My only recourse at that point is to hit CTRL-C.

   Now, looking in /usr/local/lib/php I see the following:

--------------------
[200] 19:41:56 <[EMAIL PROTECTED]:/usr/local/lib/php> ls -al
total 20
drwxr-xr-x  4 root root 4096 Jul  2 18:59 ./
drwxr-xr-x  5 root root 4096 Jul  2 18:59 ../
drwxr-xr-x  2 root root 4096 Jul  2 18:59 build/
drwxr-xr-x  3 root root 4096 Jul  2 18:59 extensions/
[201] 19:41:58 <[EMAIL PROTECTED]:/usr/local/lib/php>
--------------------

   Looking at running processes (related to this install) I get this:

--------------------
17828 pts/2    S+     0:00 make install
25312 pts/2 S+ 0:00 /bin/sh -c if test -f pear/install-pear-nozlib.phar && /usr/local/src/apache/php-5.1.4/build/shtool mkdir -p /usr/local/lib/php; then make -s install-pear-installer; else cat /usr/local/src/apache/php-5.1.4/pear/install-pear.txt; fi
25329 pts/2    S+     0:00 make -s install-pear-installer
25330 pts/2 S+ 0:00 /usr/local/src/apache/php-5.1.4/sapi/cli/php -n -dshort_open_tag=0 -dsafe_mode=0 -derror_reporting=E_ALL -dmemory_limit=-1 -ddetect_unicode=0 pear/install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin
--------------------

   It's just sitting there, doing nothing.

What's going on here? How do I even start figuring out why it won't finish the install?

   -- A

--- End Message ---
--- Begin Message ---
On Wednesday 28 June 2006 19:55, Chris wrote:
> Russbucket wrote:
> > I took an example  of a script from the PHP documentation and try to
> > connect to my database.   If I leave in the or die part of line 3, I get
> > nothing, if I comment out that part I get the echo message on line 4.
> >
> > <?php
> > // Connecting and selecting the database
> > $conn = mysql_connect ('localhost', 'finemanruss', 'XXXXXXXl') or die
> > ('Could not connect :  '  . mysql_error());
> > echo 'Connected successfully';
> > mysql_select_db ("Lions", $conn);
> >
> > // Preform SQL query
> > $query = 'SELECT * FROM Moses_Lake_Lions';
> > $result = mysql_query ($query) or die ( 'Query failed;   '  .
> > mysql_error()); ?>
> >
> > I know line three works without the or die part since I have a 2nd script
> > that is almost the same (no or die) and it retrieves info from my DB.
>
> Try it the same as the php manual page:
>
> $conn = mysql_connect('....');
> if (!$conn) {
>    die("Could not connect: " . mysql_error());
> }
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
Chris thanks for the response. I got this working and solved a couple other 
issues. Now just have one I'm working on where thedata is not being sorted 
correctly. I will be looking at that tommorrow. 

Thanks again for the response.
-- 
Russ

--- End Message ---
--- Begin Message ---
Hello,

on 06/30/2006 11:38 AM Jay Paulson said the following:
> I'd like to get some feedback on what the list thinks is a good template
> engine other than smarty.
> 
> I'd also like to do some quick prototyping using a PHP framework does anyone
> have any recommendations for one that is easy to pick up and run with?
> 
> Finally, does anyone have any suggestions for a good PHP database
> abstraction library?

You may want to take a look at this post for a few recommendations:

http://www.phpclasses.org/blog/post/52-Recommended-PHP-frameworks.html

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
Manuel Lemos wrote:

on 06/30/2006 11:38 AM Jay Paulson said the following:

I'd like to get some feedback on what the list thinks is a good template
engine other than smarty.

I'd also like to do some quick prototyping using a PHP framework does anyone
have any recommendations for one that is easy to pick up and run with?

Finally, does anyone have any suggestions for a good PHP database
abstraction library?

You may want to take a look at this post for a few recommendations:

http://www.phpclasses.org/blog/post/52-Recommended-PHP-frameworks.html

That is a nice sales pitch Manuel but takes  bit of digesting.

Jay - This is a 'how long is a piece of string' type question. So there are as many answers as there are developers here ;)

I've only ever used Smarty - and not seen anything yet to replace it.

PDO is being pushed as a DB Abstraction library, but it only 'abstracts' the calls to PHP, it does nothing to abstract the SQL if you want a truly generic solution, if you need one, but if you don't then why bother with abstraction ;)

I've been running with bitweaver now for some time, and things are starting to come together. It uses Smarty and ADOdb and can install itself on a range of database engines without any 'manual intervention'. So I am happy that it is a generic framework that is easy to run with.

www.bitweaver.org

--
Lester Caine - G8HFL
-----------------------------
L.S.Caine Electronic Services - http://home.lsces.co.uk
Model Engineers Digital Workshop - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
This one time, at band camp, Lester Caine <[EMAIL PROTECTED]> wrote:

 
> PDO is being pushed as a DB Abstraction library, but it only 'abstracts' 
> the calls to PHP, it does nothing to abstract the SQL if you want a 
> truly generic solution, if you need one, but if you don't then why 
> bother with abstraction ;)

Whoa dragon.... 

PDO is not being pushed as a DB Abstraction library. From the manual..
"PDO provides a data-access abstraction layer, which means that,
regardless of which database you're using, you use the same functions to
issue queries and fetch data. PDO does not provide a database abstraction;
it doesn't rewrite SQL or emulate missing features. 
You should use a full-blown abstraction layer if you need that facility."

As you see, PDO provides a standard interface to databases, you might use
PDO to create an abstraction layer, but is not an abstraction layer in itself.

Kind regards
Kevin

-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message ---
Kevin Waterson wrote:

This one time, at band camp, Lester Caine <[EMAIL PROTECTED]> wrote:

PDO is being pushed as a DB Abstraction library, but it only 'abstracts' the calls to PHP, it does nothing to abstract the SQL if you want a truly generic solution, if you need one, but if you don't then why bother with abstraction ;)

Whoa dragon....
PDO is not being pushed as a DB Abstraction library. From the manual..

Both other replies to this thread quoted PDO without mentioning that it not a DB Abstraction library - because the misconception is that PDO is. So I was just correcting those messages.

--
Lester Caine - G8HFL
-----------------------------
L.S.Caine Electronic Services - http://home.lsces.co.uk
Model Engineers Digital Workshop - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/
Treasurer - Firebird Foundation Inc. - http://www.firebirdsql.org/index.php

--- End Message ---
--- Begin Message ---
Jay Paulson wrote:
I'd like to get some feedback on what the list thinks is a good template
engine other than smarty.


I like ezTemplate. (E_STRICT)

I'd also like to do some quick prototyping using a PHP framework does anyone
have any recommendations for one that is easy to pick up and run with?


Seems to be a really difficult question imho :)

Finally, does anyone have any suggestions for a good PHP database
abstraction library?


Depends on your environment, MDB2 is fine if you have to run php4, otherwise, I like Zend_Db (http://framework.zend.com/manual/en/zend.db.html) and also ezDatabase (http://ez.no/doc/components/view/latest/(file)/classtrees_Database.html)
is worth a look.

just my 0,2 €cents

--- End Message ---
--- Begin Message ---
Hello,

on 06/29/2006 06:10 PM Adam Zey said the following:
>>> Hy guys I'd like to know if there is a way to update a site through
>>> sending an email. Something like this, you send an email and the body
>>> of the email substitutes a text you use in your site. Igreat apreciate
>>> any help since I couldn't find anything on this topic.
>>
>> Sure, you can send a message attaching the files you want to update in
>> your site to an address with a POP3 mailbox and then use a POP3 client
>> to retrieve and parse the message to extract the files to be updated.
>>
>> You may want to try this POP3 client class that you can use for that
>> purpose.
>>
>> It provides a cool feature that lets you retrieve messages from POP3
>> mailbox using PHP fopen or file_get_contents functions like this:
>>
>> file_get_contents('pop3://user:[EMAIL PROTECTED]/1');
>>
>> http://www.phpclasses.org/pop3class
>>
>> You can also use this message parser class that lets you process your
>> messages and extract any files easily.
>>
>> http://www.phpclasses.org/mimeparser
>>
>> Take a look at this example that demonstrates how to integrate both
>> classes easily to parse your message structure:
>>
>> http://www.phpclasses.org/browse/file/14695.html
>>
> 
> I've had to have a perl script reacting to emails and acting on them. I
> did it using RetchMail (http://open.nit.ca/wiki/?page=RetchMail), which
> is mindnumbingly fast when you need to download a bunch of emails. As
> the page says, stupidly fast. As a disclaimer, it's an opensource app
> maintained by people at my workplace. Still, it's probably the fastest
> POP3 mail fetcher out there.

You do not need Perl for this. The MIME message parser mentioned above
can perfectly process a message read from the command input. You just
need to specify php://stdin as the file name.

However, I do not recommend reading messages from the standard input
unless you do not have an alternative. There are several problems:

- You can only read the message once. You cannot process the message in
multiple passes. If your script fails for some temporary fault, the
message is lost and the sender gets a permanent bounce.

- AFAIK reading the message from the command line input is specific of
Unix/Linux systems. A POP3 based solution works regardless of the OS you
are running as long as you have POP3 mailbox associated to the e-mail
address.

- Usually you need to have shell access to configure what script will
run to processe the message. Many PHP shared hosting companies do not
provide shell access.

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
Hi all ,

 I am using PHP 4.3.2 and MYSQL .

 I need to do printing function in php .
Basically , in my client web page , it will display the list of items on the html page. And i have a print button , so that the user can print the html page to their local printer.

Any way how to do this in PHP ?

Thanks

--- End Message ---
--- Begin Message ---
weetat wrote:
Hi all ,

 I am using PHP 4.3.2 and MYSQL .

 I need to do printing function in php .
Basically , in my client web page , it will display the list of items on the html page. And i have a print button , so that the user can print the html page to their local printer.

Any way how to do this in PHP ?

No, but you can in javascript.

window.print();


--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---

Reply via email to