php-general Digest 17 Sep 2009 02:45:19 -0000 Issue 6343
Topics (messages 298086 through 298104):
Re: php/mysql Query Question.
298086 by: Peter Ford
298101 by: admin.buskirkgraphics.com
298102 by: Robert Cummings
298103 by: Jim Lucas
Re: best function to use ~ file_get_contents or ?
298087 by: Ashley Sheridan
298088 by: Andrea Giammarchi
298089 by: Ashley Sheridan
298090 by: Andrea Giammarchi
Insert Symbol into Mysql
298091 by: Samrat Kar
298092 by: Andrea Giammarchi
298093 by: Ashley Sheridan
298094 by: Andrea Giammarchi
298095 by: Ashley Sheridan
298096 by: João Cândido de Souza Neto
298097 by: Andrea Giammarchi
298098 by: Andrea Giammarchi
298099 by: Ashley Sheridan
298100 by: Andrea Giammarchi
Re: APC - Upload progress problem. apc
298104 by: Phred White
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:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
[email protected] wrote:
> Before most of you go on a rampage of how to please read below...
>
> As most of you already know when using MySQL from the shell you can write
> your queries in html format in an out file.
>
> Example: shell>mysql -uyourmom -plovesme --html
> This now will return all results in an html format from all queries.
>
> Now I could “tee” this to a file and save the results returned if I so choose
> to save the result of the display .
>
> Let’s say I want to be lazy and write a php MySQL query to do the same so
> that any result I queried for would return the html results in a table
> without actually writing the table tags in the results.
>
> Is there a mysql_connect or select_db or mysql_query tag option to do that
> since mysql can display it from the shell?
I think you'll find that the HTML output is a function of the mysql command line
program (I tend to use PostgreSQL, where 'psql' is a similar program) so you can
only access that functionality by calling the command line.
I suspect that, since PHP is a HTML processing language (originally), the
creators of the mysql_ functions figured that the user could sort out making
HTML from the data returned...
It's should be a simple operation to write a wrapper function to put HTML around
the results. There might even be a PEAR extension or PHPClasses class to do it
(I haven't looked yet)
--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent
--- End Message ---
--- Begin Message ---
I tend to do this robert,
while looking at your example i thought to myself since i am trying to mimick a
shell command why not run one.
Result:
<?
$db = 'db';
$host = 'host';
$user = 'user';
$pass = 'pass';
$query = "select * from $db.my_table";
$ddvery = shell_exec("mysql -u$user -p$pass --html --execute=$query");
echo "<pre>$ddvery</pre>";
?>
Not are the results safe but the unlimited possibilites are amazing. Thanks so
much for the kick starter
[email protected] wrote:
> Would you mind giving me an example of this that i can stick right into a
blank php file and run.
>
> I get what you are saying but i cant seem to make that even echo out the
data. php 5.2 mysql 5.1.3 Apache 2.2
<?php
$db = 'db';
$host = 'host';
$user = 'user';
$pass = 'pass';
$query = "select * from my_table";
$db = escapeShellArg( $db );
$host = escapeShellArg( $host );
$user = escapeShellArg( $user );
$pass = escapeShellArg( $pass );
$query = escapeShellArg( $query );
$command = "echo $query | mysql --html -h$host -u$user -p$pass $db";
echo 'Command: '.$command."\n";
$html = `$command`;
echo $html."\n";
?>
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
[email protected] wrote:
I tend to do this robert,
while looking at your example i thought to myself since i am trying to mimick a
shell command why not run one.
Result:
<?
$db = 'db';
$host = 'host';
$user = 'user';
$pass = 'pass';
$query = "select * from $db.my_table";
$ddvery = shell_exec("mysql -u$user -p$pass --html --execute=$query");
echo "<pre>$ddvery</pre>";
?>
Not are the results safe but the unlimited possibilites are amazing. Thanks so
much for the kick starter
This presumes your information is all safe and that there are no special
shell characters in any of the configuration settings (now and in the
future). Also, the shell_exec() function is "identical" to the backtick
operator that I used in my example (see the help). You've essentially
done what I did, but made it less robust... except for the use of the
--execute parameter which I wasn't aware existed since it's just as easy
to pipe :)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
[email protected] wrote:
> Before most of you go on a rampage of how to please read below...
>
> As most of you already know when using MySQL from the shell you can write
> your queries in html format in an out file.
>
> Example: shell>mysql -uyourmom -plovesme --html
> This now will return all results in an html format from all queries.
>
> Now I could “tee” this to a file and save the results returned if I so choose
> to save the result of the display .
>
> Let’s say I want to be lazy and write a php MySQL query to do the same so
> that any result I queried for would return the html results in a table
> without actually writing the table tags in the results.
>
> Is there a mysql_connect or select_db or mysql_query tag option to do that
> since mysql can display it from the shell?
>
Here is my rendition of an result to HTML table output function.
This is normally used within my db class
but I have modified it to work with a MySQLi result object
function debug($result) {
/* get column metadata */
$html = '<table border="1"><tr>';
foreach ( $result->fetch_fields() AS $val ) {
$html .= '<th>'.$val->name.'</th>';
}
$html .= '</tr>';
foreach ( $result->fetch_row() AS $row ) {
$html .= '<tr>';
foreach ( $row AS $value ) {
$html .= '<td> '.$value.'</td>';
}
$html .= '</tr>';
}
$html .= '</table>';
return $html;
}
Let us know if that works for you.
--- End Message ---
--- Begin Message ---
On Wed, 2009-09-16 at 12:08 +0530, Gaurav Kumar wrote:
> There is no best function as such. Everything depends upon your requirement.
>
> You can also use fopen() to get the contents of the remote file and do some
> error handling that if you get any content then display image else a message
> etc..
>
> Gaurav Kumar
> (Team Lead- open source)
> oswebstudio.com
>
>
>
> On Wed, Sep 16, 2009 at 4:06 AM, CRM <[email protected]> wrote:
>
> > Hi All,
> > Not sure of the best approach, need your feedback. I have 4 images on a
> > website. These are used in navigation. When I load a reference webpage on
> > my
> > local machine the local page calls 4 images from an external website, each
> > image will be on a different domain.
> >
> > What I want to see is if the navigation images/buttons can be
> > loaded/displayed
> > in my browser. If they can, then I will display the images on my local
> > page.
> > If the images cannot be loaded, then this indicates some connection issue
> > and
> > the result will be some text like 'Site Offline'. So just by glancing at my
> > local machine reference page I can tell if one or more of the different
> > sites
> > is or is not available.
> >
> > So what is the best function to use?
> >
> > if ( @file_get_contents( DOMAIN_PATH .
> > "images/navigation/nav_globalissa.png" )):
> >
> > or ???
> >
> > Please also cc [email protected]
> >
> > Thanks for any helpful suggestions.
> >
> > Sincerely,
> >
> > Rob
> > Global I.S. S.A.
> > Software Powers the Net
> > Email: crm at globalissa dot com
> >
> > * * * The Forge of Globalissa ~ PHP Foobar Machine * * *
> > http://globalissa.com/forge/
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
The way I've always seen this approached before is by using the wget
command, which can be asked to just return the headers for a page. In
your case you'd be looking for all 200 codes, which means that all the
sites are up. This is faster than asking to return a full image each
time.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
> The way I've always seen this approached before is by using the wget
> command, which can be asked to just return the headers for a page. In
> your case you'd be looking for all 200 codes, which means that all the
> sites are up. This is faster than asking to return a full image each
> time.
but slower 'cause for each image you need to requests
On the other hand, file_get_contents could return false positives cause the
fact we are asking for an image does not mean an image will be returned.
I would go for a curl call, where you can have both headers and content so in
one call you can handle every case. A bit slower than a HEAD request, surely
faster than a HEAD request plus the REQUEST.
One more thing, I hope you have rights to grab these images, usually there are
APIs or webservices when a website would like to share images in this way but
it does not seem the case here ...
Regards
_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
http://www.microsoft.com/windows/windowslive/products/photos.aspx
--- End Message ---
--- Begin Message ---
On Wed, 2009-09-16 at 11:17 +0200, Andrea Giammarchi wrote:
>
>
> > The way I've always seen this approached before is by using the wget
> > command, which can be asked to just return the headers for a page. In
> > your case you'd be looking for all 200 codes, which means that all the
> > sites are up. This is faster than asking to return a full image each
> > time.
>
> but slower 'cause for each image you need to requests
>
> On the other hand, file_get_contents could return false positives cause the
> fact we are asking for an image does not mean an image will be returned.
>
> I would go for a curl call, where you can have both headers and content so in
> one call you can handle every case. A bit slower than a HEAD request, surely
> faster than a HEAD request plus the REQUEST.
>
> One more thing, I hope you have rights to grab these images, usually there
> are APIs or webservices when a website would like to share images in this way
> but it does not seem the case here ...
>
> Regards
>
> _________________________________________________________________
> Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
>
> http://www.microsoft.com/windows/windowslive/products/photos.aspx
Requesting only the headers is a lot faster than requesting the headers
AND the file itself. I'd also not look to grab an image anyway, try
grabbing just the HTML of a web-page. You get the headers, and the HTML
is likely to be very small in size. Not only that, you can perform other
tests on the returned HTML, for example to see if PHP is still running
on the remote site. All of this is very easy to accomplish with a single
line call to wget.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
This is what I said, except if you want to grab the content you need to request
HEAD first and eventually GET, and this is slower than just GET parsing headers.
In any case, curl is the answer, imho.
Regards
Requesting only the headers is a lot faster than requesting the headers AND the
file itself.
_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
http://www.microsoft.com/windows/windowslive/products/photos.aspx
--- End Message ---
--- Begin Message ---
I want to insert symbols like degree, plusminus, currency along with string
into Mysql database. Front is HTML form with javascript. Server side scripts
are written in PHP. Please help.
Regards,
Samrat Kar
--- End Message ---
--- Begin Message ---
does JavaScript use the proper way to encode strings as encodeURIComponent is,
and for each sent key/value pair?
Is MySQL table charset ut8_general_ci ?
If not, do you convert sent UTF-8 charset into table charset?
In few words we miss the way/library used to send data, the default PHP
charset, the MySQL table charset, the way you store/retrieve data into MySQL,
etc etc ... we can help but we need more info
> From: [email protected]
> To: [email protected]
> Date: Wed, 16 Sep 2009 17:00:31 +0530
> Subject: [PHP] Insert Symbol into Mysql
>
> I want to insert symbols like degree, plusminus, currency along with string
> into Mysql database. Front is HTML form with javascript. Server side scripts
> are written in PHP. Please help.
>
>
>
> Regards,
>
>
>
> Samrat Kar
>
_________________________________________________________________
With Windows Live, you can organize, edit, and share your photos.
http://www.microsoft.com/middleeast/windows/windowslive/products/photo-gallery-edit.aspx
--- End Message ---
--- Begin Message ---
On Wed, 2009-09-16 at 17:00 +0530, Samrat Kar wrote:
> I want to insert symbols like degree, plusminus, currency along with string
> into Mysql database. Front is HTML form with javascript. Server side scripts
> are written in PHP. Please help.
>
>
>
> Regards,
>
>
>
> Samrat Kar
>
Two ways to do this:
1. Insert the characters as their escaped HTML codes, e.g. °
± £ (for °, ± and £)
2. Set the DB to use a utf8 character set, and insert the
characters directly as is, without escaping them
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
He has no utf-8 charset in the table, so the first point is valid and
htmlentities is the function (
http://uk.php.net/manual/en/function.htmlentities.php )
You need to remember that in this way you need to use htmlentities for
*everything*, specially for searches, otherwise ° against ° will be a "not
found".
Alternative could be mb_string for charset manipulation but since the table is
not UTF-8 you could have lots of problems with other chars ... so you change
the charset if this is a new project before you gonna be in trouble for size
and/or performances, or you convert each stored stirng via htmlentities and you
start right now to use htmlentities as default select/insert "parser" (or you
convert everything into utf-8 via mb_string and you truncate the table, change
the charset, refill it via converted values performed into another table)
Regards
> From: [email protected]
> Two ways to do this:
>
> 1. Insert the characters as their escaped HTML codes, e.g. °
> ± £ (for °, ± and £)
> 2. Set the DB to use a utf8 character set, and insert the
> characters directly as is, without escaping them
_________________________________________________________________
Share your memories online with anyone you want.
http://www.microsoft.com/middleeast/windows/windowslive/products/photos-share.aspx?tab=1
--- End Message ---
--- Begin Message ---
On Wed, 2009-09-16 at 14:47 +0200, Andrea Giammarchi wrote:
> He has no utf-8 charset in the table, so the first point is valid and
> htmlentities is the function (
> http://uk.php.net/manual/en/function.htmlentities.php )
> You need to remember that in this way you need to use htmlentities for
> *everything*, specially for searches, otherwise ° against ° will be a
> "not found".
>
> Alternative could be mb_string for charset manipulation but since the table
> is not UTF-8 you could have lots of problems with other chars ... so you
> change the charset if this is a new project before you gonna be in trouble
> for size and/or performances, or you convert each stored stirng via
> htmlentities and you start right now to use htmlentities as default
> select/insert "parser" (or you convert everything into utf-8 via mb_string
> and you truncate the table, change the charset, refill it via converted
> values performed into another table)
>
> Regards
>
> > From: [email protected]
> > Two ways to do this:
> >
> > 1. Insert the characters as their escaped HTML codes, e.g. °
> > ± £ (for °, ± and £)
> > 2. Set the DB to use a utf8 character set, and insert the
> > characters directly as is, without escaping them
>
> _________________________________________________________________
> Share your memories online with anyone you want.
> http://www.microsoft.com/middleeast/windows/windowslive/products/photos-share.aspx?tab=1
I don't recall him saying that a utf8 table was not an option or that he
wasn't using one.
Also, try not to top post ;)
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
If he´s really using a any other charset instead of utf8 table, why not
using utf8_decode and utf8_decode in his php files to solve this?
"Ashley Sheridan" <[email protected]> escreveu na mensagem
news:1253101315.2275.4.ca...@localhost...
On Wed, 2009-09-16 at 17:00 +0530, Samrat Kar wrote:
> I want to insert symbols like degree, plusminus, currency along with
> string
> into Mysql database. Front is HTML form with javascript. Server side
> scripts
> are written in PHP. Please help.
>
>
>
> Regards,
>
>
>
> Samrat Kar
>
Two ways to do this:
1. Insert the characters as their escaped HTML codes, e.g. °
± £ (for °, ± and £)
2. Set the DB to use a utf8 character set, and insert the
characters directly as is, without escaping them
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
> I don't recall him saying that a utf8 table was not an option or that he
> wasn't using one.
I know 'cause he replied directly to me rather than this ML
>
> Also, try not to top post ;)
I usually hate scroll 'till the end to find often a single row as reply ...
I'll try though
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
Thanks
_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
http://www.microsoft.com/windows/windowslive/products/photos.aspx
--- End Message ---
--- Begin Message ---
> If he´s really using a any other charset instead of utf8 table, why not
> using utf8_decode and utf8_decode in his php files to solve this?
let's say PHP could have a different charset than the one defined in that MySQL
table so this is not a portable solution, specially if you do not perfectly
know charset and problems.
Regards
_________________________________________________________________
Show them the way! Add maps and directions to your party invites.
http://www.microsoft.com/windows/windowslive/products/events.aspx
--- End Message ---
--- Begin Message ---
On Wed, 2009-09-16 at 15:40 +0200, Andrea Giammarchi wrote:
> > I don't recall him saying that a utf8 table was not an option or that he
> > wasn't using one.
>
> I know 'cause he replied directly to me rather than this ML
>
> >
> > Also, try not to top post ;)
>
> I usually hate scroll 'till the end to find often a single row as reply ...
> I'll try though
>
>
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
>
> Thanks
>
> _________________________________________________________________
> Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
>
> http://www.microsoft.com/windows/windowslive/products/photos.aspx
Yeah, the rules say to snip out parts of the convo which aren't
pertinent, but I know I don't exactly follow that one either! :-/
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
> Yeah, the rules say to snip out parts of the convo which aren't
> pertinent, but I know I don't exactly follow that one either! :-/
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
to be honest the problem is that I am in hotmail rather than gmail here, and
this page is not clever as gmail one is, quotes/replies are quite annoying here.
Thanks
_________________________________________________________________
Share your memories online with anyone you want.
http://www.microsoft.com/middleeast/windows/windowslive/products/photos-share.aspx?tab=1
--- End Message ---
--- Begin Message ---
He's baaaaack...
Well folks..
The good news is that APC and my upload progress is working! : )
The bad news is, ...kind of working. : |
It does exactly what I want, but at 1 hour of progress-barring, it
stops. I.e., APC stops returning a response for the given key. Whether
the connection has allowed 100MB, 500MB or 1GB. The file actually
continues to upload, for hours if necessary, and eventually gets there.
APC provides a sort of management page that lets you look at the APC
status, including a listing of "User Cache Entries" which includes any
still-valid upload keys, and any keys created via apc_add(). This
listing includes a Timeout value, which is "none" for the apc_add keys
and 3600 for the upload keys. Somewhat suspicious, I'd say, since the
keys stop being working after 1 hour of use.
APC lets you set a number of timeout values: apc.gc_ttl, apc.user_ttl,
apc.ttl. I have set all of these to be gianormous, but the upload key
timeout value never changes.
I can't believe that this is an inherent limitation, or nobody would
be using this. The Google claims people are using this for big
uploads, so I should be able to. I have looked through Apache/unix to
see if this limit refers to something set deeper in the system, but
everything that I know of that I can loosen up, I have.
Any ideas?
Thanks, Phred
On Sep 15, 2009, at 8:51 AM, Nathan Nobbe wrote:
On Tue, Sep 15, 2009 at 12:05 AM, Phred White
<[email protected]>wrote:
Folks:
Thanks for all your help and suggestions.
Miracle of miracles I am now getting a response,so I can start some
level
of debugging.
I am not sure exactly what has been going on. I NEVER got a
response, then
I did - when I tried uploading some different files. It seems that
larger
files always give a negative response for me. Now I am thinking
that it has
been a timing issue. My ajax stuff doesn't repeat yet, so there is
currently
only one request. It seems that if the file is a little too large,
the first
response is always false, that may be the case for very small files
too. I
finally just picked a file that was the right size.
Since I could never verify that APC was responding, it didn't occur
to me
to go ahead and iron out the ajax stuff.
Anyway now I can move forward.
Thanks all for all your suggestions, sorry this ends up being such
a stupid
conclusion.
--- End Message ---