Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,222 members, 7,829,369 topics. Date: Thursday, 16 May 2024 at 05:20 AM

Connection String To The Server In Php - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Connection String To The Server In Php (990 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)

(1) (Reply) (Go Down)

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"wink;
?>
or this
<?php
mysql_pconnect("localhost","username","password"wink;
$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 undecided
Re: Connection String To The Server In Php by deco2come: 2:09pm On Mar 12, 2011
ajaxphp7:

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"wink;
?>
or this
<?php
mysql_pconnect("localhost","username","password"wink;
$names=$_post['names'];
$state=$_post['state'];
$age=$_post['age'];
?>




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"wink;



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"wink;
?>


and


<?php
mysql_connect("$host","$user","$pass"wink;
$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"wink
mysql_connect("localhost","username","password"wink;
?>

OR

<?php
$names=$_post['names'];
$state=$_post['state'];
$age=$_post['age'];
mysql_connect("localhost","username","password"wink;
mysql_query("insert into bla bla bla"wink
?>



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?  angry tongue
Put Don anywhere, put ma babe anywhere. Nothing tie them.
Damn I miss this place.  sad
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 kiss
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)

Download My New Bbcode Editor 0.1 / Pls Who Has Jrpassphrase Pro / I Want To Create A Website

(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. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.