which one is the best?

Started on the old forum in October 2012 · view the original in the archive · old links redirect here

7 replies · 710 views · started 14 years ago · 1 min read

4 participants
jaidon20k Developer · 64 posts #1

Out of these sql statement which one is the best?

(1) $sql = "INSERT INTO members(id,firstn) VALUES('".$id."','".$fname."')";

(2) $sql = "INSERT INTO members SET id = '".$id."', firstn = '"..$fname."';

arnage Lead · 811 posts #2

And... 🙂

(3) $sql = "INSERT INTO members VALUES('".$id."','".$fname."')";

It should not be compared for the "best", the diference is that in (1) and (3) examples you have to keep order of inserting values while in (2) don't.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
$XTREME$ Developer · 82 posts #3

jaidon20k wrote: Out of these sql statement which one is the best?

(1) $sql = "INSERT INTO members(id,firstn) VALUES('".$id."','".$fname."')";

(2) $sql = "INSERT INTO members SET id = '".$id."', firstn = '"..$fname."';

$sql = "INSERT INTO members (id,firstn) VALUES('".$id."','". $fname."')"; its better ,bt injectment are open

Edyka Junior · 11 posts #4
<?php 
$sql = "INSERT INTO members(id,firstn) VALUES('".intval($id)."','".mysql_real_escape_string($fname)."')";  
?>

This would be the best way 🙂

arnage.... there are only 2 statements... no 3rd :lol

arnage Lead · 811 posts #5

$XTREME$ wrote: $sql = "INSERT INTO members (id,firstn) VALUES('".$id."','". $fname."')"; its better ,bt injectment are open

Edyka wrote:

<?php 
$sql = "INSERT INTO members(id,firstn) VALUES('".intval($id)."','".mysql_real_escape_string($fname)."')";  
?>

This would be the best way :)

Like i said, there is no the best way between this two queries as they are for different purpose. And security nor escaping is in the question. 🙂 But when you mentioned, intval() should not be used here and it returns floats also where $id can't be float plus on invalid sets 0. And its quoted wrong. 😉

Read this http://coding-talk.com/f60/protecting-your-users-session-url-session-vars-%24_session-%24_cookie-17514/ and list Tutorials forum a little. 🙂

Edyka wrote: arnage.... there are only 2 statements... no 3rd :lol

Yes, it have. 😉

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
Edyka Junior · 11 posts #6

Not in the original post 🙂 the one by you can be ignored... that is just an example 😀 why not? intval returns only ints as I know? .... PS your PHP knowledge is great, but your english could use some training 🙂 PHP: intval - Manual returns only integers .. 🙂 and the best thing is the most seruced one 🙂 I bet the guy who opened the theme meant to ask for the more secure one 🙂

arnage Lead · 811 posts #7

No. Floats, hex, minus values also. Read, read, read... PHP: intval - Manual ... and posted link before.

And please, stay on topic, no one cares about my or anyones english nor personality. That attitude leave at Serbian forums. 😉

Edyka wrote: PHP: intval - Manual returns only integers .. 🙂 and the best thing is the most seruced one 🙂 I bet the guy who opened the theme meant to ask for the more secure one :)

echo intval('-42');                   // -42
echo intval(042);                     // 34
echo intval(1e10);                    // 1410065408
echo intval('1e10');                  // 1
echo intval(0x1A);                    // 26

A? READ!

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
jaidon20k Developer · 64 posts #8

Edyka wrote: Not in the original post 🙂 the one by you can be ignored... that is just an example 😀 why not? intval returns only ints as I know? .... PS your PHP knowledge is great, but your english could use some training 🙂 PHP: intval - Manual returns only integers .. 🙂 and the best thing is the most seruced one 🙂 I bet the guy who opened the theme meant to ask for the more secure one :)

thanks@ Edyka

i mean which one is more secure?

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close