Call Custom MySql Function In Doctrine Query builders Query
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
i am having an error while using custom mysql function in doctrine query builders query string.
[Syntax Error] line 0, col 32: Error: Expected known function, got 'ucfirst'
mysql function is as below.
DELIMITER $$
DROP FUNCTION IF EXISTS `ucfirst`$$
CREATE FUNCTION `ucfirst`(str_value VARCHAR(5000)) RETURNS varchar(5000) CHARSET latin1 DETERMINISTIC
BEGIN
RETURN CONCAT(UCASE(LEFT(str_value, 1)),SUBSTRING(str_value, 2));
END$$
DELIMITER;
Doctrine query code is as below.
$qb = $this->em->createQueryBuilder();
$qb->select("ConcatWs(' ',ucfirst(p.firstName), ucfirst(p.lastName)) as user_name");
$qb->from('EntityProfile', 'p');
$data = $qb->getQuery()->getResult();
print_r($data);exit;
any suggestions where i am doing wrong ?
php mysql doctrine-orm mysql-function
add a comment |
i am having an error while using custom mysql function in doctrine query builders query string.
[Syntax Error] line 0, col 32: Error: Expected known function, got 'ucfirst'
mysql function is as below.
DELIMITER $$
DROP FUNCTION IF EXISTS `ucfirst`$$
CREATE FUNCTION `ucfirst`(str_value VARCHAR(5000)) RETURNS varchar(5000) CHARSET latin1 DETERMINISTIC
BEGIN
RETURN CONCAT(UCASE(LEFT(str_value, 1)),SUBSTRING(str_value, 2));
END$$
DELIMITER;
Doctrine query code is as below.
$qb = $this->em->createQueryBuilder();
$qb->select("ConcatWs(' ',ucfirst(p.firstName), ucfirst(p.lastName)) as user_name");
$qb->from('EntityProfile', 'p');
$data = $qb->getQuery()->getResult();
print_r($data);exit;
any suggestions where i am doing wrong ?
php mysql doctrine-orm mysql-function
add a comment |
i am having an error while using custom mysql function in doctrine query builders query string.
[Syntax Error] line 0, col 32: Error: Expected known function, got 'ucfirst'
mysql function is as below.
DELIMITER $$
DROP FUNCTION IF EXISTS `ucfirst`$$
CREATE FUNCTION `ucfirst`(str_value VARCHAR(5000)) RETURNS varchar(5000) CHARSET latin1 DETERMINISTIC
BEGIN
RETURN CONCAT(UCASE(LEFT(str_value, 1)),SUBSTRING(str_value, 2));
END$$
DELIMITER;
Doctrine query code is as below.
$qb = $this->em->createQueryBuilder();
$qb->select("ConcatWs(' ',ucfirst(p.firstName), ucfirst(p.lastName)) as user_name");
$qb->from('EntityProfile', 'p');
$data = $qb->getQuery()->getResult();
print_r($data);exit;
any suggestions where i am doing wrong ?
php mysql doctrine-orm mysql-function
i am having an error while using custom mysql function in doctrine query builders query string.
[Syntax Error] line 0, col 32: Error: Expected known function, got 'ucfirst'
mysql function is as below.
DELIMITER $$
DROP FUNCTION IF EXISTS `ucfirst`$$
CREATE FUNCTION `ucfirst`(str_value VARCHAR(5000)) RETURNS varchar(5000) CHARSET latin1 DETERMINISTIC
BEGIN
RETURN CONCAT(UCASE(LEFT(str_value, 1)),SUBSTRING(str_value, 2));
END$$
DELIMITER;
Doctrine query code is as below.
$qb = $this->em->createQueryBuilder();
$qb->select("ConcatWs(' ',ucfirst(p.firstName), ucfirst(p.lastName)) as user_name");
$qb->from('EntityProfile', 'p');
$data = $qb->getQuery()->getResult();
print_r($data);exit;
any suggestions where i am doing wrong ?
php mysql doctrine-orm mysql-function
php mysql doctrine-orm mysql-function
asked Jan 3 at 7:23


Amit JoshiAmit Joshi
181215
181215
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Doctrine stays on top of DBAL - abstraction layer for database access, its purpose is to hide details of implementation of particular database. DQL, query language defined by Doctrine, is also built in a way to remain generic enough. It means that Doctrine is designed in a way to provide unified interface and hence provides no built-in facilities for use some database-specific extensions.
However Doctrine is flexible enough to let you to extend DQL AST and implement required database-specific extensions by yourself. In particular custom DQL function (that needs to be mapped to actual SQL) can be created by implementing own FunctionNode
and register it as additional functional node into EntityManager
configuration. In your case it will be $em->getConfiguration()->addCustomStringFunction()
.
Please refer Doctrine documentation for example of custom function implementation.
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017980%2fcall-custom-mysql-function-in-doctrine-query-builders-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Doctrine stays on top of DBAL - abstraction layer for database access, its purpose is to hide details of implementation of particular database. DQL, query language defined by Doctrine, is also built in a way to remain generic enough. It means that Doctrine is designed in a way to provide unified interface and hence provides no built-in facilities for use some database-specific extensions.
However Doctrine is flexible enough to let you to extend DQL AST and implement required database-specific extensions by yourself. In particular custom DQL function (that needs to be mapped to actual SQL) can be created by implementing own FunctionNode
and register it as additional functional node into EntityManager
configuration. In your case it will be $em->getConfiguration()->addCustomStringFunction()
.
Please refer Doctrine documentation for example of custom function implementation.
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
add a comment |
Doctrine stays on top of DBAL - abstraction layer for database access, its purpose is to hide details of implementation of particular database. DQL, query language defined by Doctrine, is also built in a way to remain generic enough. It means that Doctrine is designed in a way to provide unified interface and hence provides no built-in facilities for use some database-specific extensions.
However Doctrine is flexible enough to let you to extend DQL AST and implement required database-specific extensions by yourself. In particular custom DQL function (that needs to be mapped to actual SQL) can be created by implementing own FunctionNode
and register it as additional functional node into EntityManager
configuration. In your case it will be $em->getConfiguration()->addCustomStringFunction()
.
Please refer Doctrine documentation for example of custom function implementation.
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
add a comment |
Doctrine stays on top of DBAL - abstraction layer for database access, its purpose is to hide details of implementation of particular database. DQL, query language defined by Doctrine, is also built in a way to remain generic enough. It means that Doctrine is designed in a way to provide unified interface and hence provides no built-in facilities for use some database-specific extensions.
However Doctrine is flexible enough to let you to extend DQL AST and implement required database-specific extensions by yourself. In particular custom DQL function (that needs to be mapped to actual SQL) can be created by implementing own FunctionNode
and register it as additional functional node into EntityManager
configuration. In your case it will be $em->getConfiguration()->addCustomStringFunction()
.
Please refer Doctrine documentation for example of custom function implementation.
Doctrine stays on top of DBAL - abstraction layer for database access, its purpose is to hide details of implementation of particular database. DQL, query language defined by Doctrine, is also built in a way to remain generic enough. It means that Doctrine is designed in a way to provide unified interface and hence provides no built-in facilities for use some database-specific extensions.
However Doctrine is flexible enough to let you to extend DQL AST and implement required database-specific extensions by yourself. In particular custom DQL function (that needs to be mapped to actual SQL) can be created by implementing own FunctionNode
and register it as additional functional node into EntityManager
configuration. In your case it will be $em->getConfiguration()->addCustomStringFunction()
.
Please refer Doctrine documentation for example of custom function implementation.
answered Jan 3 at 10:57
FlyingFlying
3,4442919
3,4442919
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
add a comment |
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
hello, i have created custom doctrine extensions but dont know how to create custom mysql function. can you elaborate it with example ?
– Amit Joshi
Jan 10 at 9:43
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
@AmitJoshi this is hard part of Doctrine that requires knowledge of internal representation of DQL AST and related areas. I have no working example and there is little documentation on this topic, you can try to check this part of documentation for examples.
– Flying
Jan 10 at 10:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017980%2fcall-custom-mysql-function-in-doctrine-query-builders-query%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown