Connecting Tech Pros Worldwide Help | Site Map

Call to undefined function: query()

muelli75
Guest
 
Posts: n/a
#1: Sep 28 '05
Hi!

Im getting insane by solving a problem ....

I try to define a function which uses a code-snippet from another file.
My base are the codes from the great book "WebDataBase-Book by H.
Williams & D. Lane".

So I try to use


$result = $connection->query("LOCK TABLES visitkarte WRITE");
if(DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);


which works in another .inc very fine.

Look at my .inc for the function VKDataInDB



<?php
require_once "db.inc";
require_once "DB.php";
require_once "authenticate.inc";
require_once "visitsontheweb.inc";

// Dieser Errorhandler ist extrem gefährlich da er das root-passwort
der DB ausgibt!
//set_error_handler("customHandler");

function VKDataInDB(&$connection)
{
//Book Page 641

$connection=DB::connect($dsn, true);
$cust_id=getCust_id($_SESSION["loginUsername"]);

// Lock Table -- 636
$result = $connection->query("LOCK TABLES visitkarte WRITE");
if(DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);

//Query for the highest ID
$result = $connection->query("SELECT max(vk_id) FROM visitkarte");
if (DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);

// Die nächste verfügbare vk_id errechnen
$vk_id = $row["max(vk_id)"] + 1;

//selbst erstellt
$sql = "INSERT INTO visitkarte cust_id = '{$cust_id}',
vk_id = '{$vk_id}',
erstelldatum = NOW(),
sessionid = '{SID}',
vorname = '{$_SESSION['vorname']}',
nachname = '{$_SESSION['nachname']}',
titel = (),
plz ='{$_SESSION['plz']}',
ort ='{$_SESSION['ort']}',
tel1 ={$_SESSION['telefonnummer']},
mobil=(),
strasse={$_SESSION['strasse']},
homepage=(),
email={$_SESSION['email']},
kategorie={$_SESSION['kategorie']},
hintergrund=(1),
";

//Write data
mysql_query ($sql) or mysql_error();

// Unlock tables
$result=$connection->query("UNLOCK TABLES");
if(DB::isError($result))
trigger_error($result->getMessage(), E_USER_ERROR);

}
?>


When I call this include.file, i get the following error:

Fatal error: Call to undefined function: query() in
/raid-1/APACHE/hausstein/www/visits/includes/vkdbfunc.inc on line 18

OK, I havent defined "query" in my .incs, but why works it on another
place? And why must I declare the variable "$connection" when I dont
have to do it on another place.
My "require"-section is extended like in the basefiles form the book.

Questions enough for many answers!

Thanks in advance,

Martin

Kirsten
Guest
 
Posts: n/a
#2: Sep 29 '05

re: Call to undefined function: query()


muelli75 schrieb:[color=blue]
> Hi!
>
> Im getting insane by solving a problem ....
>
> I try to define a function which uses a code-snippet from another file.
> My base are the codes from the great book "WebDataBase-Book by H.
> Williams & D. Lane".
>
> So I try to use
>
>
> $result = $connection->query("LOCK TABLES visitkarte WRITE");
> if(DB::isError($result))
> trigger_error($result->getMessage(), E_USER_ERROR);
>
>
> which works in another .inc very fine.
>
> Look at my .inc for the function VKDataInDB
>
>
>
> <?php
> require_once "db.inc";
> require_once "DB.php";
> require_once "authenticate.inc";
> require_once "visitsontheweb.inc";
>
> // Dieser Errorhandler ist extrem gefährlich da er das root-passwort
> der DB ausgibt!
> //set_error_handler("customHandler");
>
> function VKDataInDB(&$connection)
> {
> //Book Page 641
>
> $connection=DB::connect($dsn, true);
> $cust_id=getCust_id($_SESSION["loginUsername"]);
>
> // Lock Table -- 636
> $result = $connection->query("LOCK TABLES visitkarte WRITE");
> if(DB::isError($result))
> trigger_error($result->getMessage(), E_USER_ERROR);
>
> //Query for the highest ID
> $result = $connection->query("SELECT max(vk_id) FROM visitkarte");
> if (DB::isError($result))
> trigger_error($result->getMessage(), E_USER_ERROR);
> $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
>
> // Die nächste verfügbare vk_id errechnen
> $vk_id = $row["max(vk_id)"] + 1;
>
> //selbst erstellt
> $sql = "INSERT INTO visitkarte cust_id = '{$cust_id}',
> vk_id = '{$vk_id}',
> erstelldatum = NOW(),
> sessionid = '{SID}',
> vorname = '{$_SESSION['vorname']}',
> nachname = '{$_SESSION['nachname']}',
> titel = (),
> plz ='{$_SESSION['plz']}',
> ort ='{$_SESSION['ort']}',
> tel1 ={$_SESSION['telefonnummer']},
> mobil=(),
> strasse={$_SESSION['strasse']},
> homepage=(),
> email={$_SESSION['email']},
> kategorie={$_SESSION['kategorie']},
> hintergrund=(1),
> ";
>
> //Write data
> mysql_query ($sql) or mysql_error();
>
> // Unlock tables
> $result=$connection->query("UNLOCK TABLES");
> if(DB::isError($result))
> trigger_error($result->getMessage(), E_USER_ERROR);
>
> }
> ?>
>
>
> When I call this include.file, i get the following error:
>
> Fatal error: Call to undefined function: query() in
> /raid-1/APACHE/hausstein/www/visits/includes/vkdbfunc.inc on line 18
>
> OK, I havent defined "query" in my .incs, but why works it on another
> place? And why must I declare the variable "$connection" when I dont
> have to do it on another place.
> My "require"-section is extended like in the basefiles form the book.
>
> Questions enough for many answers!
>
> Thanks in advance,
>
> Martin
>[/color]
Hi,

auch wenns Deutsch ginge ;)

Try to replace $result->getMessage() with $result->getDebugInfo()
and see a better error discription.

-Kirsten
Closed Thread