I have been writing some scripts for webpages, which use a mysql database. There's only one database which should be used, but I've been communication with mysql using mysql_db_query($db, $query, $sql) in my scripts.

Does anyone know if mysql_query($query, $sql) is faster ? Does mysql_db_query() use an extra mysql_select_db() every time I use it? Or doesn't it mean that much?

Some of my scripts have ten to 20 queries in them, so it would mean a lot on performance / speed, if there are differences between the two strategies.

wimmel

    I'm not sure of the mechanics PHP uses, but it would seem logical that it passes a USE db-name to MySQL every time you use mysql_db_query. If you are only using 1 db throughout the script there is absolutely no benefit to using mysql_db_query over mysql_query and it may be detrimental.

      2 months later

      the only point of mysql_db_query is to avoid having to issue a separate mysql_select_db command at the beginning of the session or when changing databases.
      What you should do is issue the mysql_select_db command once at the beginning of the session or only if you need to change the database you are querying and otherwise use plain mysql_query.

        Write a Reply...