Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
tommyb
Hangin' Around



Joined: May 31, 2006
Posts: 49

PostPosted: Wed Jul 05, 2006 4:54 am Reply with quote

Hello all,

When a user creates a script and they have a query such as
Code:
$query="select * form table";

$result=mysql_query($query, $dbi);
What is the purpose of the $dbi? I know it is the database connection info in config.php but surely if the config.php file is already included why would you have need for this?

Many Thanks
 
View user's profile Send private message
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6437

PostPosted: Wed Jul 05, 2006 5:57 am Reply with quote

Although that is the old style connection variable (the new one is $db and isn't mySQL-specific), it contains the connection information necessary to access the database. Without it, you would need to provide connection information (e.g. user, password) every time you wanted to access the database.

_________________
I search, therefore I exist...
Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
tommyb







PostPosted: Wed Jul 05, 2006 6:57 am Reply with quote

So if I had module that refers to $dbi should that still connect to ravennuke or should it be changed to $db?And does it only need to be referenced once for all queries to work or if mysql_close() is encountered? Sorry if this seems basic I'm just trying to work things out by looking at various modules etc and trying to understand them more.
 
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Wed Jul 05, 2006 8:09 am Reply with quote

I'm not a real expert on object oriented programming but if you look at a couple of programs in the /db directory you can see how this works. First look at db.php and you will see that it includes a different php file for each database type that you could possibly access in nuke. Then in the included file (let's say mysql4.php) there are a series of objects created that essentially "abstract" the details of database access and queries. So, if you read thru the sql_query function you will see all the details that it takes care to let you call a query "simply" in your program.

Then if you look at a simple query say from mainfile.php you will see something like this:

$result = $db->sql_query('SELECT * FROM '.$prefix.'_config');

and I believe that what it's doing is using the sql_query object from the appropriate program in the /db directory and because that object already has built in the query methods you don't need to implement the details in each database call.

I'm struggling to say that in english but it's what I think is going on.

Probably should add that a lot of the database "base" info that the programs in the /db directory use are stored in config.php.
 
View user's profile Send private message Visit poster's website
tommyb







PostPosted: Wed Jul 05, 2006 8:12 am Reply with quote

I think I get it $db refers to the database type therefore if it is mysql
$result = $db->sql_query() would relate to
$result= mysql_query()

or $result = equivalent_query(function) for db type.

And making it this way allows for users of various database types without them having to troubleshoot why it is not working.Smile
 
gregexp
The Mouse Is Extension Of Arm



Joined: Feb 21, 2006
Posts: 1497
Location: In front of a screen....HELP! lol

PostPosted: Wed Jul 05, 2006 9:53 am Reply with quote

correct, It also puts the variable in an array declaring it, never to be redeclared(I believe).

_________________
For those who stand shall NEVER fall and those who fall shall RISE once more!! 
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
kguske







PostPosted: Wed Jul 05, 2006 10:30 am Reply with quote

Actually, $db is an object that represents the database connection, regardless of which database you use (e.g. MySQL, Postgres, SQL Server, etc.). sql_query is a function that executes a database query on that database, again, regardless of which database.

The rest of your comparison is correct. But it also simplifies database access for all modules and addons by providing a consistent way to access data.
 
gregexp







PostPosted: Wed Jul 05, 2006 10:35 am Reply with quote

so sql_query is a new function redifined in nuke and $db is the database connection?

now thats somethin new.
I just thought that $db was earlier defined as MY or pos or whatever typ(mine being mysql)
and when placed like that
it actually read mysql_query.
Thanx, learning things twice.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©