0

I am having mobile app connecting to Server database (MYSQL db). I know the best practice is NOT to expose database credential to mobile app level (security reasons).Best practice to let mobile app connect to PHP code on server side. this PHP api has DB credentials and serves mobile app with required data.

Issue : since all mobile app users are connecting to save server API (API connects to MYSQL database as single user), I am getting error : "Connection failed: User xxxxx has exceeded the 'max_connections_per_hour' resource (current value: 500)"

Server side PHP API is :

  <?php
  include 'DatabaseConfig.php';

 // Create connection
$conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
} 
 switch ($tasknum ) {

 case “get name”:  // Request type 1
      $sql="INSERT INTO xxx  (CustomerID,xyz) VALUES ($custid,’xy’z)”; 
      $result = $conn->query($sql);
     break; 

 case “get task”:
      $sql="INSERT INTO yyy  (CustomerID,xdd) VALUES ($custid,’zzz’)”; 
      $result = $conn->query($sql);

         echo $sql; 
      break;     
  default:
                echo “request task not handled”  ;    
} 

any proposals? Thanks..

waleed.makarem
  • 179
  • 2
  • 9
  • Each connection handle must be released. Are you disconencting properly in the php part after each request has done interacting with database. i.e. connect , then run queries , then disconnect. this will release the connection handle. so for next request you can make a new connection. – Rode093 Jun 24 '23 at 11:58
  • i have added my php code (server side api). I assume that after each php call , database connection will be close/destructed automatically. If not , what shall be proper setup – waleed.makarem Jun 24 '23 at 12:31
  • It does not close the connection. Try finishing the execution process by calling $conn->close(); in the end – Rode093 Jun 24 '23 at 19:28
  • did it , but same issue. Gets same error though closing connection. – waleed.makarem Jun 24 '23 at 20:18
  • try the solution in this thread https://stackoverflow.com/questions/19034583/mysql-error-exceeded-the-max-connections-per-hour – Rode093 Jun 24 '23 at 21:17
  • access denied. My hosting is at hostinger, cloud plan. Do you have proposal for got hosting provider to meet ~ 100,000 db calls/hour – waleed.makarem Jun 25 '23 at 11:41

0 Answers0