Page 1 of 1

SQL with PHP

Posted: Fri Sep 20, 2002 3:19 pm
by Johnm
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

Posted: Fri Sep 20, 2002 3:22 pm
by nielsene
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....

Posted: Fri Sep 20, 2002 3:24 pm
by JPlush76
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

Posted: Fri Sep 20, 2002 3:27 pm
by Johnm
Yes, that is what I mean, building outside the function. I guess I did not write it like I was thinking it.

Direwolf

Posted: Fri Sep 20, 2002 3:31 pm
by Johnm
I include my dabase connect too.

Direwolf

Posted: Sat Sep 21, 2002 9:17 am
by Takuma
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. :D