What is the difference?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Can you tell me if there's a relevant difference between the codes below?



$stmtLA = "SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'mv' ORDER BY id DESC LIMIT 6";
$IDLA = $conn->query($stmtLA);


And



$IDLA = $conn->query("SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'nv' ORDER BY id DESC LIMIT 6");


I have many queries like this one, to get records from my db and print on the screen. I was thinking if i get performance if i use the 'single line' query.










share|improve this question


















  • 6





    You won't get a better performance if you save yourself a variable.

    – juergen d
    Nov 16 '18 at 15:46






  • 1





    formato = 'nv' vs formato = 'mv' is a difference in the queries so they should return different results. Maybe there was an intention to make the value "mv" variable? This can be done by preparing the query in a variable with PDO

    – Sander Visser
    Nov 16 '18 at 15:54













  • @SanderVisser Nop, this is just random values. Just to ask here

    – nobody
    Nov 16 '18 at 15:59




















0















Can you tell me if there's a relevant difference between the codes below?



$stmtLA = "SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'mv' ORDER BY id DESC LIMIT 6";
$IDLA = $conn->query($stmtLA);


And



$IDLA = $conn->query("SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'nv' ORDER BY id DESC LIMIT 6");


I have many queries like this one, to get records from my db and print on the screen. I was thinking if i get performance if i use the 'single line' query.










share|improve this question


















  • 6





    You won't get a better performance if you save yourself a variable.

    – juergen d
    Nov 16 '18 at 15:46






  • 1





    formato = 'nv' vs formato = 'mv' is a difference in the queries so they should return different results. Maybe there was an intention to make the value "mv" variable? This can be done by preparing the query in a variable with PDO

    – Sander Visser
    Nov 16 '18 at 15:54













  • @SanderVisser Nop, this is just random values. Just to ask here

    – nobody
    Nov 16 '18 at 15:59
















0












0








0








Can you tell me if there's a relevant difference between the codes below?



$stmtLA = "SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'mv' ORDER BY id DESC LIMIT 6";
$IDLA = $conn->query($stmtLA);


And



$IDLA = $conn->query("SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'nv' ORDER BY id DESC LIMIT 6");


I have many queries like this one, to get records from my db and print on the screen. I was thinking if i get performance if i use the 'single line' query.










share|improve this question














Can you tell me if there's a relevant difference between the codes below?



$stmtLA = "SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'mv' ORDER BY id DESC LIMIT 6";
$IDLA = $conn->query($stmtLA);


And



$IDLA = $conn->query("SELECT `title`, `audio`, `capa`, `link`, `alt` FROM table WHERE type = 'tes' AND formato = 'nv' ORDER BY id DESC LIMIT 6");


I have many queries like this one, to get records from my db and print on the screen. I was thinking if i get performance if i use the 'single line' query.







mysql sql pdo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 15:45









nobodynobody

849




849








  • 6





    You won't get a better performance if you save yourself a variable.

    – juergen d
    Nov 16 '18 at 15:46






  • 1





    formato = 'nv' vs formato = 'mv' is a difference in the queries so they should return different results. Maybe there was an intention to make the value "mv" variable? This can be done by preparing the query in a variable with PDO

    – Sander Visser
    Nov 16 '18 at 15:54













  • @SanderVisser Nop, this is just random values. Just to ask here

    – nobody
    Nov 16 '18 at 15:59
















  • 6





    You won't get a better performance if you save yourself a variable.

    – juergen d
    Nov 16 '18 at 15:46






  • 1





    formato = 'nv' vs formato = 'mv' is a difference in the queries so they should return different results. Maybe there was an intention to make the value "mv" variable? This can be done by preparing the query in a variable with PDO

    – Sander Visser
    Nov 16 '18 at 15:54













  • @SanderVisser Nop, this is just random values. Just to ask here

    – nobody
    Nov 16 '18 at 15:59










6




6





You won't get a better performance if you save yourself a variable.

– juergen d
Nov 16 '18 at 15:46





You won't get a better performance if you save yourself a variable.

– juergen d
Nov 16 '18 at 15:46




1




1





formato = 'nv' vs formato = 'mv' is a difference in the queries so they should return different results. Maybe there was an intention to make the value "mv" variable? This can be done by preparing the query in a variable with PDO

– Sander Visser
Nov 16 '18 at 15:54







formato = 'nv' vs formato = 'mv' is a difference in the queries so they should return different results. Maybe there was an intention to make the value "mv" variable? This can be done by preparing the query in a variable with PDO

– Sander Visser
Nov 16 '18 at 15:54















@SanderVisser Nop, this is just random values. Just to ask here

– nobody
Nov 16 '18 at 15:59







@SanderVisser Nop, this is just random values. Just to ask here

– nobody
Nov 16 '18 at 15:59














1 Answer
1






active

oldest

votes


















0














The first version creates a throw-away variable that's then used in the query. The second version just runs the query.



There's no difference in terms of performance, but in the first there is a risk here that you may misfire and execute the wrong query.



I strongly recommend following the second style because you've loaded the query directly and it's visually obvious what's executing. In the former it's possible to have two slightly similar variables with two completely different queries in use, like $sql3 and $sql8 which at a quick glance might seem identical.






share|improve this answer
























  • Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

    – nobody
    Nov 16 '18 at 15:53











  • In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

    – tadman
    Nov 16 '18 at 15:54













  • As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

    – nobody
    Nov 16 '18 at 15:57













  • You can see a full example of my code here: pastebin.com/ShvbLQKu

    – nobody
    Nov 16 '18 at 16:10











  • Since the query itself has no dynamic components there's no difference.

    – tadman
    Nov 16 '18 at 16:29












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341152%2fwhat-is-the-difference%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









0














The first version creates a throw-away variable that's then used in the query. The second version just runs the query.



There's no difference in terms of performance, but in the first there is a risk here that you may misfire and execute the wrong query.



I strongly recommend following the second style because you've loaded the query directly and it's visually obvious what's executing. In the former it's possible to have two slightly similar variables with two completely different queries in use, like $sql3 and $sql8 which at a quick glance might seem identical.






share|improve this answer
























  • Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

    – nobody
    Nov 16 '18 at 15:53











  • In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

    – tadman
    Nov 16 '18 at 15:54













  • As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

    – nobody
    Nov 16 '18 at 15:57













  • You can see a full example of my code here: pastebin.com/ShvbLQKu

    – nobody
    Nov 16 '18 at 16:10











  • Since the query itself has no dynamic components there's no difference.

    – tadman
    Nov 16 '18 at 16:29
















0














The first version creates a throw-away variable that's then used in the query. The second version just runs the query.



There's no difference in terms of performance, but in the first there is a risk here that you may misfire and execute the wrong query.



I strongly recommend following the second style because you've loaded the query directly and it's visually obvious what's executing. In the former it's possible to have two slightly similar variables with two completely different queries in use, like $sql3 and $sql8 which at a quick glance might seem identical.






share|improve this answer
























  • Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

    – nobody
    Nov 16 '18 at 15:53











  • In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

    – tadman
    Nov 16 '18 at 15:54













  • As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

    – nobody
    Nov 16 '18 at 15:57













  • You can see a full example of my code here: pastebin.com/ShvbLQKu

    – nobody
    Nov 16 '18 at 16:10











  • Since the query itself has no dynamic components there's no difference.

    – tadman
    Nov 16 '18 at 16:29














0












0








0







The first version creates a throw-away variable that's then used in the query. The second version just runs the query.



There's no difference in terms of performance, but in the first there is a risk here that you may misfire and execute the wrong query.



I strongly recommend following the second style because you've loaded the query directly and it's visually obvious what's executing. In the former it's possible to have two slightly similar variables with two completely different queries in use, like $sql3 and $sql8 which at a quick glance might seem identical.






share|improve this answer













The first version creates a throw-away variable that's then used in the query. The second version just runs the query.



There's no difference in terms of performance, but in the first there is a risk here that you may misfire and execute the wrong query.



I strongly recommend following the second style because you've loaded the query directly and it's visually obvious what's executing. In the former it's possible to have two slightly similar variables with two completely different queries in use, like $sql3 and $sql8 which at a quick glance might seem identical.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 15:48









tadmantadman

158k19182211




158k19182211













  • Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

    – nobody
    Nov 16 '18 at 15:53











  • In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

    – tadman
    Nov 16 '18 at 15:54













  • As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

    – nobody
    Nov 16 '18 at 15:57













  • You can see a full example of my code here: pastebin.com/ShvbLQKu

    – nobody
    Nov 16 '18 at 16:10











  • Since the query itself has no dynamic components there's no difference.

    – tadman
    Nov 16 '18 at 16:29



















  • Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

    – nobody
    Nov 16 '18 at 15:53











  • In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

    – tadman
    Nov 16 '18 at 15:54













  • As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

    – nobody
    Nov 16 '18 at 15:57













  • You can see a full example of my code here: pastebin.com/ShvbLQKu

    – nobody
    Nov 16 '18 at 16:10











  • Since the query itself has no dynamic components there's no difference.

    – tadman
    Nov 16 '18 at 16:29

















Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

– nobody
Nov 16 '18 at 15:53





Alright, but i would get any security against attacks, if i put the SELECT into a variable, like the first version?

– nobody
Nov 16 '18 at 15:53













In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

– tadman
Nov 16 '18 at 15:54







In both cases this is 100% dependent on the query being safe. The only difference is the direct operation versus indirect operation. To secure your query be absolutely certain you're using prepared statements with placeholder values. The query you show here has no dynamic data, so there's no way to comment on security issues. If you introduce user data into your actual query you may have huge problems. query(...) cannot deal with user data. prepare() can.

– tadman
Nov 16 '18 at 15:54















As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

– nobody
Nov 16 '18 at 15:57







As i said, i use this query to get records from my db and print on the screem (with a foreach loop), it's not even on the user-side. So do you think that i should use prepared statements with placeholder values?

– nobody
Nov 16 '18 at 15:57















You can see a full example of my code here: pastebin.com/ShvbLQKu

– nobody
Nov 16 '18 at 16:10





You can see a full example of my code here: pastebin.com/ShvbLQKu

– nobody
Nov 16 '18 at 16:10













Since the query itself has no dynamic components there's no difference.

– tadman
Nov 16 '18 at 16:29





Since the query itself has no dynamic components there's no difference.

– tadman
Nov 16 '18 at 16:29




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341152%2fwhat-is-the-difference%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python