Raw SQL results

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ®ed Eye Media - ®ichard Grove

    Raw SQL results

    Hopefully someone can help.

    If you query a mysql database with a command line, you get results.
    eg: select * FROM table WHERE foo='bar' //would produce
    +------------+
    | foo |
    +------------+
    | bar |
    +------------+
    1 row in set (0.00 sec)

    Is there anyway to use php to output this raw sql result?
    I would simply like to echo out the whole lot (above)

    Regards
    Richard Grove


  • rush

    #2
    Re: Raw SQL results

    "®ed Eye Media - ®ichard Grove" <info@redeyemed ia.co.uk> wrote in message
    news:402b5750$0 $44570$65c69314 @mercury.nildra m.net...[color=blue]
    > Hopefully someone can help.
    >
    > If you query a mysql database with a command line, you get results.
    > eg: select * FROM table WHERE foo='bar' //would produce
    > +------------+
    > | foo |
    > +------------+
    > | bar |
    > +------------+
    > 1 row in set (0.00 sec)[/color]

    If you need exactly that appearance, (wit -- + and |)I think you could
    call from php shell command for mysql, and then capture output from it and
    replace newlines with <br>. Look-up in manual for excuting shell commands.

    rush
    --
    Get your very own domain easily. Fast and professional customer service.



    Comment

    • Pedro Graca

      #3
      Re: Raw SQL results

      ®ed Eye Media - ®ichard Grove wrote:
      X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
      [color=blue]
      > If you query a mysql database with a command line, you get results.
      > eg: select * FROM table WHERE foo='bar' //would produce
      > +------------+
      > | foo |
      > +------------+
      > | bar |
      > +------------+
      > 1 row in set (0.00 sec)
      >
      > Is there anyway to use php to output this raw sql result?
      > I would simply like to echo out the whole lot (above)[/color]


      not tested on Windows

      Code:
      <?php
      $data = `echo "select * from database.table where foo='bar';" | mysql -uusername -ppassword -t`;
      echo "<pre>$data</pre>\n";
      ?>
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • ®ed Eye Media - Richard Grove

        #4
        Re: Raw SQL results


        "Pedro Graca" <hexkid@hotpop. com> wrote in message
        news:c0fq3k$174 6kk$1@ID-203069.news.uni-berlin.de...[color=blue]
        > ®ed Eye Media - ®ichard Grove wrote:
        > X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
        >[color=green]
        > > If you query a mysql database with a command line, you get results.
        > > eg: select * FROM table WHERE foo='bar' //would produce
        > > +------------+
        > > | foo |
        > > +------------+
        > > | bar |
        > > +------------+
        > > 1 row in set (0.00 sec)
        > >
        > > Is there anyway to use php to output this raw sql result?
        > > I would simply like to echo out the whole lot (above)[/color]
        >
        >
        > not tested on Windows
        >
        >
        Code:
        > <?php
        > $data = `echo "select * from database.table where foo='bar';" |[/color]
        mysql -uusername -ppassword -t`;[color=blue]
        > echo "<pre>$data</pre>\n";
        > ?>
        >
        > --[/color]


        All this does it output the query, not the results.
        Regards
        RG


        Comment

        • Kevin Thorpe

          #5
          Re: Raw SQL results

          ®ed Eye Media - Richard Grove wrote:[color=blue]
          > "Pedro Graca" <hexkid@hotpop. com> wrote in message
          > news:c0fq3k$174 6kk$1@ID-203069.news.uni-berlin.de...
          >[color=green]
          >>®ed Eye Media - ®ichard Grove wrote:
          >>X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
          >>
          >>[color=darkred]
          >>>If you query a mysql database with a command line, you get results.
          >>>eg: select * FROM table WHERE foo='bar' //would produce
          >>>+------------+
          >>>| foo |
          >>>+------------+
          >>>| bar |
          >>>+------------+
          >>>1 row in set (0.00 sec)
          >>>
          >>>Is there anyway to use php to output this raw sql result?
          >>>I would simply like to echo out the whole lot (above)[/color]
          >>
          >>
          >>not tested on Windows
          >>
          >>
          Code:
          >><?php
          >>$data = `echo "select * from database.table where foo='bar';" |[/color]
          >
          > mysql -uusername -ppassword -t`;
          >[color=green]
          >>echo "<pre>$data</pre>\n";
          >>?>
          >>
          >>--[/color]
          >
          >
          >
          > All this does it output the query, not the results.
          > Regards
          > RG
          >[/color]
          those are backticks (top left key on my keyboard) not apostrophes.

          backticks execute the string inside them and return the result.

          Comment

          • Pedro Graca

            #6
            Re: Raw SQL results

            Kevin Thorpe wrote:
            User-Agent: Mozilla/5.0 (Windows; ...[color=blue][color=green]
            >> "Pedro Graca" <hexkid@hotpop. com> wrote in message
            >> news:c0fq3k$174 6kk$1@ID-203069.news.uni-berlin.de...[color=darkred]
            >>>
            >>>not tested on Windows
            >>>
            >>>
            Code:
            >>><?php
            >>>$data = `echo "select * from database.table where foo='bar';" |[/color]
            >>
            >> mysql -uusername -ppassword -t`;
            >>[color=darkred]
            >>>echo "<pre>$data</pre>\n";
            >>>?>
            >>>
            [/color]
            >>[/color]
            > those are backticks (top left key on my keyboard) not apostrophes.
            >
            > backticks execute the string inside them and return the result.[/color]

            Does it work in Windows (I don't have PHP or MySQL here at work)?

            or do you have to do something like the following?

            Code:
            $data = `mysql -uusername -ppassword -t < echo "select * from db.table"`;

            I tried a few different things, it appears this syntax should work
            --
            --= my mail box only accepts =--
            --= Content-Type: text/plain =--
            --= Size below 10001 bytes =--

            Comment

            • ®ed Eye Media - Richard Grove

              #7
              Re: Raw SQL results


              "Pedro Graca" <hexkid@hotpop. com> wrote in message
              news:c0g3it$16j e8s$1@ID-203069.news.uni-berlin.de...[color=blue]
              > Kevin Thorpe wrote:
              > User-Agent: Mozilla/5.0 (Windows; ...[color=green][color=darkred]
              > >> "Pedro Graca" <hexkid@hotpop. com> wrote in message
              > >> news:c0fq3k$174 6kk$1@ID-203069.news.uni-berlin.de...
              > >>>
              > >>>not tested on Windows
              > >>>
              > >>>
              Code:
              > >>><?php
              > >>>$data = `echo "select * from database.table where foo='bar';" |
              > >>
              > >> mysql -uusername -ppassword -t`;
              > >>
              > >>>echo "<pre>$data</pre>\n";
              > >>>?>
              > >>>
              > >>[/color]
              > > those are backticks (top left key on my keyboard) not apostrophes.
              > >
              > > backticks execute the string inside them and return the result.[/color]
              >
              > Does it work in Windows (I don't have PHP or MySQL here at work)?
              >
              > or do you have to do something like the following?
              >
              >
              Code:
              > $data = `mysql -uusername -ppassword -t < echo "select * from db.table"`;
              >
              >
              >
              > I tried a few different things, it appears this syntax should work
              > --[/color]


              Doesn't work this end.
              Thanks anyway
              RG


              Comment

              • Pedro Graca

                #8
                Re: Raw SQL results

                ®ed Eye Media - Richard Grove wrote:[color=blue]
                >
                > "Pedro Graca" <hexkid@hotpop. com> wrote in message
                > news:c0g3it$16j e8s$1@ID-203069.news.uni-berlin.de...[color=green]
                >>
                >>
                Code:
                >> $data = `mysql -uusername -ppassword -t < echo "select * from db.table"`;
                >>
                [/color][/color]
                [color=blue]
                > Doesn't work this end.
                > Thanks anyway[/color]

                What happens if you type that into a DOS command-prompt window?

                C:\DOS> mysql -hLOCALHOST -uUSERNAME -pPASSWORD -t < echo "select * from db.table"

                ( remember to replace LOCALHOST, USERNAME, and PASSWORD )
                --
                --= my mail box only accepts =--
                --= Content-Type: text/plain =--
                --= Size below 10001 bytes =--

                Comment

                Working...