Re: [PHP] Using PHP files from Ajax and from other PHP files

2007-04-17 Thread Richard Lynch
On Tue, April 17, 2007 4:00 pm, Otto Wyss wrote:
> I want move all database access into separate PHP files so I could use
> these files either through an Ajax call from the client or in another
> PHP files (require_once) on the server. Is this possible? What
> interface
>   would be needed? Has anybody else tried something similar?

Putting all your database functions into one file that can be
include'd from your web application or from your AJAX response scripts
seems like a reasonable thing to me.

Go for it.

> Since I plan use Json as the data format for Ajax what overhead would
> that mean to decode again already Json encoded result if used on the
> server? Is there a workaround for Json in case of Ajax but none when
> using in other PHP files?

Whatever overhead there is to JSON encode/decode, the alternative of
not decoding/encoding correctly is not an option...

I doubt that it's a significant performance bottleneck, at least in
PHP5 where JSON is in C.

If you're in PHP4 with JSON in PHP script code, it could be "slow"

Only you on your hardware in your application with your needs can
determine if "slow" is "too slow" or "acceptable"

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Using PHP files from Ajax and from other PHP files

2007-04-17 Thread Edward Vermillion


On Apr 17, 2007, at 4:00 PM, Otto Wyss wrote:

I want move all database access into separate PHP files so I could  
use these files either through an Ajax call from the client or in  
another PHP files (require_once) on the server. Is this possible?  
What interface  would be needed? Has anybody else tried something  
similar?


Since I plan use Json as the data format for Ajax what overhead  
would that mean to decode again already Json encoded result if used  
on the server? Is there a workaround for Json in case of Ajax but  
none when using in other PHP files?




Sure you can...

Just have a variable set to specify the return format. Something like  
$_POST['retFormat'] = 'foo'; foo could be json for a JSON return,  
array for a php file return... whatever you come up with.


Then just process the request based on that value.

Any processing is going to have overhead, and you're going to need  
some kind of communication layer to allow javascript and php to  
interact, whether it's JSON or XML or even some kind of other odd  
format that you come up with yourself. There's no way around it if  
that's what you want to do.


Try googleing for php+ajax, there's a lot of this stuff out there now.

Ed

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



[PHP] Using PHP files from Ajax and from other PHP files

2007-04-17 Thread Otto Wyss
I want move all database access into separate PHP files so I could use 
these files either through an Ajax call from the client or in another 
PHP files (require_once) on the server. Is this possible? What interface 
 would be needed? Has anybody else tried something similar?


Since I plan use Json as the data format for Ajax what overhead would 
that mean to decode again already Json encoded result if used on the 
server? Is there a workaround for Json in case of Ajax but none when 
using in other PHP files?


O. Wyss

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