Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Quick Question 1

Status
Not open for further replies.

Nematoth

Programmer
Joined
Mar 29, 2002
Messages
48
Location
MY
I can't find out what this 'thing' does:

-> (is it something to do with passing a value into that function or something..

For example:
Code:
<?php
class foo
{
   function do_foo()
   {
       echo "Doing foo.";
   }
}

$bar = new foo;
$bar->do_foo();
?>

Hope someone can explain this simple problem to me.
TIA.

Thomas Shearer
Multimedia Developer
 
Lets break it down:

This is what we call a "class", you use this when you do object oriented programming. Proper Definition: A class is a definition of a structure that contains properties (variables) and methods (functions). So we have this class.
Code:
class foo
{
   function do_foo()
   {
       echo "Doing foo.";
   }
}

Here, we are creating a new object. An object is formed by specifying the "new" keyword, and assigning a class that it belongs to. In this particular snippet, you are telling the script to create a variable $bar, and make a new object using the foo class. You are then telling it to run the "do_foo()" function from the class that $bar is defined to.
$bar = new foo;
$bar->do_foo();

So, all of that, just to echo the words "Do foo."

___________________________________
[morse]--... ...--[/morse], Eric.
 
ok.. thanks for that Eric..

What about this bit of code:

Code:
function get_db_value_dom($sql)
{
  global $db_domino;
  $db_look = new DB_Sql();
  $db_look->Database = $db_domino->Database;
  $db_look->User     = $db_domino->User;
  $db_look->Password = $db_domino->Password;
  $db_look->Host     = $db_domino->Host;

  $db_look->query($sql);
  if($db_look->next_record())
    return $db_look->f(0);
  else
    return "";
  $db_domino->disconnect();
  
}

Specifically the last section.. the if/else statement. I think this means that $db_look variable(part of the newly defined class, DB_sql) is being set to the value of the SQL query passed into the function.. then if there is a record it is passing that records value into the array f()

Is that correct?




Thomas Shearer
Multimedia Developer
 
Well, sort of. Whats hapening is that it is creating a new object, and manipulating that object with the different functions in that class.

Step by step:
This imports the variable $db_domino from outside the function:
global $db_domino;

This is basically creating a new object, and storing all of the database connection info into it, which it is getting from the imported object, $db_domino
$db_look = new DB_Sql();
$db_look->Database = $db_domino->Database;
$db_look->User = $db_domino->User;
$db_look->Password = $db_domino->Password;
$db_look->Host = $db_domino->Host;

This is running the query on the database and storing the results in the object:
$db_look->query($sql);

This is saying, if a record exists, return it (I think, im not sure whats in the next_record() function in the class). If it doesnt find one, return nothing and disconnect from the database.

if($db_look->next_record())
return $db_look->f(0);
else
return "";
$db_domino->disconnect();


___________________________________
[morse]--... ...--[/morse], Eric.
 
Oh yeah, about f(0), I think that is something that gets built into the object, but it looks like its just returning the first instance by the "0"

___________________________________
[morse]--... ...--[/morse], Eric.
 
Thats great Eric. I'm doing a bit of integration and although I do have some knowledge in PHP your posts have helped me understand it a lot better.

Cheers!

N.

Thomas Shearer
Multimedia Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top