LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP MySQL code (https://www.linuxquestions.org/questions/programming-9/php-mysql-code-95598/)

pnh73 09-22-2003 03:24 PM

PHP MySQL code
 
I am writing code using PHP and making use of PEAR. When i run my script (i am using scripts from a book) i get the following error:

Quote:

Fatal error: Call to undefined function: query() in /home/linHost/www/dev/_lib/_classes/class.news.php on line 233
Does anybody have any idea why this might be?

TIA

nephilim 09-24-2003 06:46 AM

Looks like you're calling a function that doesn't exist. Could you post the piece of code around line 233, especially the call to function query()?

pnh73 09-24-2003 11:15 AM

Ok here is line 233:

Code:

        if (DB::isError($rsTmp = $this->_oConn->query($sql))) {

            catchExc($rsTmp->getMessage());
            return false;
        }


then 09-24-2003 12:22 PM

Quote:

Originally posted by pnh73
Ok here is line 233:

Code:

        if (DB::isError($rsTmp = $this->_oConn->query($sql))) {

            catchExc($rsTmp->getMessage());
            return false;
        }


Please help us help you.

* check if there is a function called query() in the file or in include files, if any.
* post the content of the query function.
* has PEAR been setup as per instruction i.e. is it in a place where PHP can find it?

regards
theN

pnh73 09-24-2003 01:36 PM

OK i found the following in common.php in /usr/share/pear/DB
Code:

// }}}
    // {{{ query()

    /**
    * Send a query to the database and return any results with a
    * DB_result object.
    *
    * @access public
    *
    * @param string $query  the SQL query or the statement to prepare
    * @param string $params the data to be added to the query
    * @return mixed a DB_result object or DB_OK on success, a DB
    *                error on failure
    *
    * @see DB::isError
    * @see DB_common::prepare
    * @see DB_common::execute
    */
    function &query($query, $params = array()) {
        if (sizeof($params) > 0) {
            $sth = $this->prepare($query);
            if (DB::isError($sth)) {
                return $sth;
            }
            $ret = $this->execute($sth, $params);
            $this->freePrepared($sth);
            return $ret;
        } else {
            $result = $this->simpleQuery($query);
            if (DB::isError($result) || $result === DB_OK) {
                return $result;
            } else {
                return new DB_result($this, $result);
            }
        }
    }

strangely DB.php (which is the include for the class.news.php file) does not contain an include for common.php
PEAR has been setup with the installatino script provided and has also had the includes for it included in the .htaccess and is a default include shown in phpinfo()

What is going on here?

then 09-25-2003 01:36 AM

.

then 09-25-2003 01:39 AM

Quote:

function &query($query, $params = array())
I'm stumped by the & in the function definition :(. Wait for one of the elders to respond to your question.

You could try your luck on the PHP forums at - http://www.phpbuilder.com/, http://www.sitepointforums.com/.

Sorry couldn't be of any help. If you do resolve the problem, please post the answers here.

regards
theN

sk8guitar 09-25-2003 06:12 PM

hi, i don't know PEAR but i know in php/mysql if your sql command has the wrong syntax it gives you an error "mysql_query() not a function" or something almost exactly like your error. doulbe check tom ake sure the $sql command you are using is actually correct.

pnh73 09-26-2003 12:30 PM

The sql query, AFAIK is correct as this is code that I got from a book and I have seen a working example at http://wrox.mediatemple.net

sk8guitar 09-26-2003 06:13 PM

did you try the sql query in the sql prompt?

pnh73 09-27-2003 08:03 AM

Running the query, which is
Code:

SELECT news_type_id,news_type FROM holiday_news_types
works fine.

Going to inspect logs etc. see if i can find anthing there. I have seen hints that it may be DSN difinition is incorrect, but i have checked and it seems to be fine.

pnh73 09-29-2003 10:27 AM

Help? Does any1 know anything more?

Robert0380 09-29-2003 01:48 PM

if mysql_query() doesnt work, then maybe php wasnt compiled with mysql.

pnh73 09-29-2003 01:56 PM

Quote:

Originally posted by Robert0380
if mysql_query() doesnt work, then maybe php wasnt compiled with mysql.
not using mysql_query().... read thread...


All times are GMT -5. The time now is 06:08 AM.