Efficient Connection To MySQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • emrahayanoglu@gmail.com

    #1

    Efficient Connection To MySQL

    Hello Everyone,

    I have question about efficient usage of connecting to mysql. Now, i'm
    using 6 or 7 queries in a page with ajax. In Addition to that, i open
    connection to mysql for every query. I think it isn't efficient way.
    However, when i open only one connection to use for every query, php
    interpreter gives error. What should i do for efficent use of
    connecting to mysql?

    Have a Good Day!

    Emrah

  • SquishedOrange@gmail.com

    #2
    Re: Efficient Connection To MySQL

    You should be able to send more than one query to mysql through one
    connection.

    Can you show the code please?

    You could also use a persistant connection if your site is in frequent
    use and your host supports it. mysql_pconnect( ). I would hesitate
    before using that though...

    If you say connecting to database takes "3" in processing time.
    Sending a select query takes about 1. **
    So your performing 4 for every query, which is very inefficient.


    ** Depends on server type, installation & load.

    Comment

    • Jerry Stuckle

      #3
      Re: Efficient Connection To MySQL

      SquishedOrange@ gmail.com wrote:
      You should be able to send more than one query to mysql through one
      connection.
      >
      True. I normally use one connection per page.
      Can you show the code please?
      >
      You could also use a persistant connection if your site is in frequent
      use and your host supports it. mysql_pconnect( ). I would hesitate
      before using that though...
      >
      Ugh. Don't even suggest this. Unless the site's getting around 1M or
      more hits per day persistent connections take more resources than they save.
      If you say connecting to database takes "3" in processing time.
      Sending a select query takes about 1. **
      So your performing 4 for every query, which is very inefficient.
      >
      >
      ** Depends on server type, installation & load.
      >
      Definitely. You do not need a new connection for each query. Just
      learn to keep track of your connections.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Andy Hassall

        #4
        Re: Efficient Connection To MySQL

        On 31 Oct 2006 11:39:52 -0800, "emrahayanoglu@ gmail.com"
        <emrahayanoglu@ gmail.comwrote:
        >I have question about efficient usage of connecting to mysql. Now, i'm
        >using 6 or 7 queries in a page with ajax. In Addition to that, i open
        >connection to mysql for every query. I think it isn't efficient way.
        What proportion of time is actually spent on connection vs the rest of the
        script - benchmark it and address the parts you can measure to be costly rather
        than guessing.
        >However, when i open only one connection to use for every query, php
        >interpreter gives error. What should i do for efficent use of
        >connecting to mysql?
        What error do you get?

        Since you mention AJAX then each of these requests is a new PHP request -
        you're not perhaps trying to open a MySQL connection in the "parent" page and
        then assuming the MySQL connection resource variable will be available in the
        requests serving the AJAX events?

        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        Working...