I am trying to run a simple SELECT
query but I get the following error:
Access denied for user ''@'localhost' (using password: NO)
It seems like I'm not connected to MySQL with my username and password, but I do have a PDO object with my connection parameters :
$_connection = new PDO('mysql:host='.$PARAM_host.';port='.$PARAM_port.';dbname='.$PARAM_dbname,
$PARAM_user, $PARAM_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
How can I use this connection to execute my query? Here's the query that works in my DBMS:
public static function getRoleByCuID($id){
$sql = "SELECT `RoleDetail_ID` ";
$sql .= "FROM common.role_detail ";
$sql .= "WHERE `RoleDetail_ID` IN (SELECT `RoleDetail_ID` ";
$sql .= "FROM common.role_application ";
$sql .= "WHERE `RoleApplication_ID` IN (SELECT `RoleApplication_ID` ";
$sql .= "FROM common.habilitation WHERE `CommonUser_ID` = '".$id."' AND `Application_ID` ='".APP_ID."'));";
//This is where the error is returned, in the 'or die' part
$result = mysql_query($sql) or die("Erreur de la requete 1 (serviceRole) ".$sql.mysql_error() );
if(mysql_num_rows($result) != 0){
return mysql_result($result, 0, 'RoleDetail_ID');
}
else {
return 0;
}
}
I could pass the PDO object in the function but then I don't know where to use it !