MySql variables and php

后端 未结 2 1681
-上瘾入骨i
-上瘾入骨i 2021-01-22 06:57

I am getting an error with this in php. What is the correct way to format this string to pass to mysql_query() in php?

SELECT count(*) FROM agents INTO @AgentCo         


        
2条回答
  •  天涯浪人
    2021-01-22 07:24

    You can only have one query at a time in PHP.

     $query1 = "SELECT count(*) FROM agents INTO @AgentCount"
     $query2="  
      SELECT user_agent_parsed, user_agent_original, COUNT( user_agent_parsed ) AS thecount, 
      COUNT( * ) / ( @AgentCount) AS percentage
      FROM agents
      GROUP BY user_agent_parsed
      ORDER BY thecount DESC LIMIT 50";
    

    UPDATE

    I have a DAL that contains all my queries. A typical function in my DAL looks like this:

    // These functions are reusable 
      public function getAllRows($table)
      {
        $sql =" SELECT * FROM $table";
        $this->query($sql);
        return $this->query_result;       
      }
    

    Then in my BLL (Business Layer) I have the following:

      public function getUserAgents()
      {
          $result = parent::getAllRows();
          $row = mysql_fetch_array($result);
          return $row[0]; // Retrieves the first row
    
          // Then you take this value and to a second request. Then return the answer / rows.
      }
    

提交回复
热议问题