PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Fri Sep 20, 2002 3:19 pm
Is there a good reason you guys use the query functions (like mysql_querry()) or did I learn to do this in an in-efficient way?
Here is a standard query in my eyes... can it be better?
Code: Select all
<?php
$sql="select ".$basename."
from bases
where job='".$session_infoї'order']."'
and loc_code=$session_infoї'loc_code'])."'";
$qry=ifx_query($sql,$dbid);
$tmp=ifx_fetch_row($qry,"next");
ifx_free_result($qry);
?>
Thanks,
Direwolf
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Fri Sep 20, 2002 3:22 pm
How is your way any different? Or are you just referring to building the query up outside of the function call? (I do that, too).
You're still using a _query function....
JPlush76
Forum Regular
Posts: 819 Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:
Post
by JPlush76 » Fri Sep 20, 2002 3:24 pm
here's how I do all my queries... using a function file that I include on my database pages
FUNCTION FILE
Code: Select all
<?php
//***** MAKE DATABASE CONNECTION
$dbhost = 'localhost';
$dbuname = 'user';
$dbpass = 'password';
$dbname = 'dev';
function dbconnect()
{
global $dbhost, $dbuname, $dbpass, $dbname;
mysql_connect($dbhost, $dbuname, $dbpass);
@mysql_select_db($dbname) or die ("Unable to select database");
}
//***** QUERY MYSQL RESULTS
function query_db($query)
{
dbconnect();
return @mysql_query($query);
}
?>
Then in the page I want to do a query I do
Code: Select all
<?php
require_once("functionfile.php");
$result = query_db("sql select statement here");
?>
so all I need is one line and it saves alot of typing
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Fri Sep 20, 2002 3:27 pm
Yes, that is what I mean, building outside the function. I guess I did not write it like I was thinking it.
Direwolf
Johnm
Forum Contributor
Posts: 344 Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:
Post
by Johnm » Fri Sep 20, 2002 3:31 pm
I include my dabase connect too.
Direwolf
Takuma
Forum Regular
Posts: 931 Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:
Post
by Takuma » Sat Sep 21, 2002 9:17 am
I wrote a class that does all the functions I need with db, so I just include that. It's saves me loads and loads of typing.