My SQL

Function / Procedure 권한

grant create, alter routine on db.* to 'id'@'%';
flush PRIVILEGES;

GRANT EXECUTE ON FUNCTION `db`.`functionName` TO 'id'@'%'
flush PRIVILEGES;

AWS RDS 를 사용하는 경우, 슈퍼 권한이 없어서 바로 권한 부여가 어려움.
AWS > RDS > 파라미터 그룹 > log_bin_trust_function_creators > 값 1

MySQL Procedure 실행오류 in PHP

  • 오류 메시지 : MYSQL query error : Commands out of sync; you can't run this command now
  • 원인 : 보통 쿼리를 두가지 이상 실행할때 발생하는 오류
  • 해결 : 새로운 쿼리문이 실행되기 전에 메모리에 기존의 것을 제거시켜준다

## 1. PHP 
...
res = mysql_perform_query(conn, "...");
...
mysql_free_result(conn); # <<추가
mysql_perform_query(conn, "...");



## 2. CI (CodeIgniter)
 # 2-1) 아래 파일에 함수 추가
 # /system/database/drivers/mysqli/mysqli_result.php
 function next_result()
 {
     if (is_object($this->conn_id))
     {
         return mysqli_next_result($this->conn_id);
     }
 }

 # 2-2) 실행단
$queryStr = "CALL functionName(parameter)";
$query = $this->db->query($queryStr);
$res = $query->result();

//add this two line 
$query->next_result();
$query->free_result();
//end of new code

return $res;
 

Subscribe to Keun's newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox. It's free!
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!