Stats: 3,189,714 members, 7,938,169 topics. Date: Monday, 02 September 2024 at 07:05 PM |
Nairaland Forum / Science/Technology / Webmasters / Connection String To The Server In Php (1038 Views)
Freehostia.com Cannot Display Content Of File Hosted On The Server. / The Server Hosting My Site Has Been Down Pls Help !!! / Which Is The Fastest Internet Connection In Nigeria (2) (3) (4)
Connection String To The Server In Php by ajaxphp7: 12:45pm On Mar 08, 2011 |
Please tell me what comes first my tied variables or the connection string, I was drawn into an arguement with one of my programming collegue. The connection string to the server or the variable tied to the text fields. Which is better this <?php $names=$_post['names']; $state=$_post['state']; $age=$_post['age']; mysql_pconnect("localhost","username","password" ![]() ?> or this <?php mysql_pconnect("localhost","username","password" ![]() $names=$_post['names']; $state=$_post['state']; $age=$_post['age']; ?> |
Re: Connection String To The Server In Php by instinctg(m): 11:30am On Mar 09, 2011 |
its always safer to assign variables first before using them in any scope. but in both codes, the syntax of the 2nd code is better and safer, since the declared variables are not used for database connectivity.Reason is because, for any variable (POST, SESSION, GET, REQUEST etc) to be set , there might be database authentication required |
Re: Connection String To The Server In Php by ajaxphp7: 1:28pm On Mar 12, 2011 |
Thamks so much for the contribution |
Re: Connection String To The Server In Php by yawatide(f): 1:52pm On Mar 12, 2011 |
To directly answer your question, I don't think it matters what order you use. After all, the strings you use for database connection have not connection to what you are capturing in the forms (In your example above, what does "name" have to do with "username" or "password". Having said that, I like to make my database connection towards the end as IMHO, it makes no sense to waste valuable server resources opening a connection when the data I am capturing hasn't been properly validated. Who knows? Maybe my approach above staves off potential security attacks. I just have never thought of it that way ![]() |
Re: Connection String To The Server In Php by deco2come: 2:09pm On Mar 12, 2011 |
ajaxphp7: The two codes are ok. But I will definitely go with the second code. One more suggestion, don't forget to use the filter/mysql escape, for security reasons. |
Re: Connection String To The Server In Php by DualCore1: 2:25pm On Mar 12, 2011 |
Wetin concern $names=$_post['names']; $state=$_post['state']; $age=$_post['age']; with mysql_connect("localhost","username","password" ![]() You will have a real cause to worry if you had any of the following scenarios Act 1 Scene 1 <?php $host=$_post['host']; $user=$_post['user']; $pass=$_post['pass']; mysql_connect("$host","$user","$pass" ![]() ?> and <?php mysql_connect("$host","$user","$pass" ![]() $host=$_post['host']; $user=$_post['user']; $pass=$_post['pass']; ?> Act 1 Scene 2 <?php $names=$_post['names']; $state=$_post['state']; $age=$_post['age']; mysql_query("insert into bla bla bla" ![]() mysql_connect("localhost","username","password" ![]() ?> OR <?php $names=$_post['names']; $state=$_post['state']; $age=$_post['age']; mysql_connect("localhost","username","password" ![]() mysql_query("insert into bla bla bla" ![]() ?> Certainly you gotta declare before you use. Ever tried to pay money into a bank account without stating the account first? Na my account e don enter naw, by dedault. Ehn, its like having dunpuzo on one hand and one of my babes on the other hand and having troubles figuring out who to put first. Wetin consign donpuzo and my babe, does he want to die young? ![]() ![]() Put Don anywhere, put ma babe anywhere. Nothing tie them. Damn I miss this place. ![]() |
Re: Connection String To The Server In Php by Nobody: 6:58pm On Mar 12, 2011 |
No Difference though the second one is more sexier ![]() |
Re: Connection String To The Server In Php by Nobody: 6:45pm On Mar 13, 2011 |
muy muy bien, - hasta la vista baby |
(1) (Reply)
I Need Help From A Php And .NET Programmer / Script For Sale / I Want Something Like Www.churchplus.com.ng
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19 |