Re: Formatting MySQL Queries
| From: | Brent Anderson | Date: | Wed, 24 Jan 2007 21:51:45 +0000 |
| Subject: | Re: Formatting MySQL Queries | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42968@lists.php.net to get a copy of this message | ||
Hello.
Just as I posted this, I found a MySQL example on php.net and was able to modify it to fit my needs. Here is the script:
<?php
// Connecting, selecting database
$link = mysql_connect('server', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('database') or die('Could not select database');
// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Printing results in Tab/Return delimited format
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "$col_value\t";} echo "\n"; } // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?> Thanks to Steven Cruz and Jeremy Glover for their quick replies, but this will be perfect. Thanks, Brent Anderson On Jan 24, 2007, at 2:20 PM, Brent Anderson wrote:
Hello. My team and I are looking for a way to return an entire table of MySQL data with columns delimited by tabs and rows delimited by carriage returns. How exactly would this work - I'm not a PHP expert and, although I know MySQL, I don't know where to begin with formatting a query pointer into an actual pile of text. We have an engine ready to take tables in this format for processing, we just need to parse the query data into a text result. Thanks, Brent Anderson