Re: [PHP] php/mysql Query Question.

2009-09-16 Thread admin
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




ad...@buskirkgraphics.com 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

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



Re: [PHP] php/mysql Query Question.

2009-09-16 Thread Robert Cummings



ad...@buskirkgraphics.com 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

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



Re: [PHP] php/mysql Query Question.

2009-09-16 Thread Jim Lucas
ad...@buskirkgraphics.com 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:   shellmysql -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=1tr';
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 .= 'tdnbsp;'.$value.'/td';
}
$html .= '/tr';
}
$html .= '/table';
return $html;
}

Let us know if that works for you.


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



[PHP] php/mysql Query Question.

2009-09-15 Thread admin
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:   shellmysql -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?

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



Re: [PHP] php/mysql Query Question.

2009-09-15 Thread Robert Cummings



ad...@buskirkgraphics.com 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:   shellmysql -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?


echo Select * from my_table | mysql --html -ufoo -pfee database_name

However, this allows for your database password to be visible in the 
process list for a brief moment of time. You might be better served by 
finer grained process control where you can check the output and provide 
input as needed. Or a simple expect script might suffice.


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



Re: [PHP] php/mysql Query Question.

2009-09-15 Thread Robert Cummings

ad...@buskirkgraphics.com 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



[PHP] PHP - mySQL query question

2004-07-25 Thread Karl-Heinz Schulz
I have a simple question (not for me).

Why does this query does not work?

$links_query = mysql_query(select id, inserted, title, information,
international from links WHERE international = y; order by inserted desc
LIMIT 0 , 30);

The information for the international fields are:

Field: international
Type: char(1)
Null: No
Default:n

The error is - Warning: mysql_fetch_row(): supplied argument is not a valid
MySQL result resource in


TIA



Tracking #: BC19379918870340BDA57FD3E349C2D0B4B484BC

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



Re: [PHP] PHP - mySQL query question

2004-07-25 Thread John W. Holmes
Karl-Heinz Schulz wrote:
I have a simple question (not for me).
Why does this query does not work?
$links_query = mysql_query(select id, inserted, title, information,
international from links WHERE international = y; order by inserted desc
LIMIT 0 , 30);
The information for the international fields are:
Field: international
Type: char(1)
Null: No
Default:n
The error is - Warning: mysql_fetch_row(): supplied argument is not a valid
MySQL result resource in
Your query has failed. You'd know this if you checked mysql_error() 
after running your query.

$result = mysql_query(...) or die(mysql_error())
Your query fails because you need quotes around the y and you need to 
remove the semi-colon.

$links_query = mysql_query(select id, inserted, title, information,
international from links WHERE international = 'y' order by inserted 
desc LIMIT 0 , 30) or die(mysql_error());

Also, why are you selecting the international column when you're 
filtering the results to rows that have y for international. You 
already know what international is, why select it in your query?

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PHP - mySQL query question

2004-07-25 Thread Jason Davidson
single quote 'y'

Jason

On Sun, 25 Jul 2004 11:05:23 -0400, Karl-Heinz Schulz
[EMAIL PROTECTED] wrote:
 I have a simple question (not for me).
 
 Why does this query does not work?
 
 $links_query = mysql_query(select id, inserted, title, information,
 international from links WHERE international = y; order by inserted desc
 LIMIT 0 , 30);
 
 The information for the international fields are:
 
 Field: international
 Type: char(1)
 Null: No
 Default:n
 
 The error is - Warning: mysql_fetch_row(): supplied argument is not a valid
 MySQL result resource in
 
 TIA
 
 Tracking #: BC19379918870340BDA57FD3E349C2D0B4B484BC
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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