LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   php function->query(variable) what's that? (https://www.linuxquestions.org/questions/programming-9/php-function-query-variable-whats-that-453526/)

osio 06-10-2006 04:21 PM

php function->query(variable) what's that?
 
I can understand basic php and some php-mysql, but there is something I bumped into when reading some e-commerce scripts.
$rs = $objDB->query($sql);

PHP Code:

function SetProducts($tbl,$ProductTitle,$Price...)
    {
        global 
$objDB;
        
$sql "Insert into $tbl(ProductTitle,Price...)";
        
$rs $objDB->query($sql);
    } 

What does '->query($sql)' do?
Thanks.

Bebo 06-10-2006 04:50 PM

The "->" notation is used for classes. I'm not very good at it, but I think the syntax is "class->object_or_function_in_class". In your example objDB is the class and query is a function in that class. Have a look at php.net for more info.

YankeeFan 06-10-2006 08:38 PM

$connectionObj->query() is...
 
Bebo is correct. It is a function of the pear db class. Your sql query is stored in the variable $sql. By itself, it does nothing. The pear db class is a means or a vehicle to access your database and tables. The "->query($sql) simply is a method (functions in classes are referred to as methods) that sends and executes your query on your database/table(s).


See more at: http://pear.php.net/manual/en/packag...ntro-query.php

Description

PEAR DB provides several methods for querying databases. The most direct method is query(). It takes a SQL query string as an argument. There are three possible returns: a new DB_result object for queries that return results (such as SELECT queries), DB_OK for queries that manipulate data (such as INSERT queries) or a DB_Error object on failure.

osio 06-12-2006 06:48 AM

pear query() method
 
Thanks a lot Bebo and YankeeFan


All times are GMT -5. The time now is 11:24 PM.