Re: mysql_query(): supplied argument is not a valid MySQL-Link resource

From: Paul Barfoot (Paul_at_theglobalfamily.fsworld.co.uk)
Date: 01/15/05


Date: Sat, 15 Jan 2005 20:53:06 -0000

Hi aa

When I had my first attempt at using functions in a PHP script I had similar
problems. I got round it by passing all variables outside the function into
it in the function call.

function write_table()
{
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
......
}
write_table();

becomes

function write_table($channel)
{
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $channel);
......
}
write_table($chan);

See if that helps.

-- 
Paul Barfoot
"aa" <aa@virgin.net> wrote in message 
news:41e8fdb1$0$22490$ed2619ec@ptn-nntp-reader03.plus.net...
>I looked up "PHP and MySQL Web Developement" by Luke Welling and Laura
> Thomson.
> In the para "Scope of variables" it reads (the book is translated into
> Russian and I translate is back into English):
> "Variables declared as global in a scenario are seen throughout the
> scenario, but not seen from within functions. By default all the variables
> declared in a scenario outside functions are global."
>
> It looks like if query MySQL from a function, I will have to put all the
> database related variables inside the function. And therefore to open and
> close a connection to the database very time I run a query.
> In my case I am building a page by sending different queries to the
> database.
> Opening and closing the connection for every query looks like an 
> unnecessary
> overhead.
>
> Can I get round it?
>
>
>
> 


Relevant Pages

  • Strange Bug
    ... I have a pretty simple PHP script. ... displays data out of the database. ... Maybe there is a solution other than dumping my query to the ... string, and string of dashes) but that doesn't work. ...
    (comp.lang.php)
  • Build_DB PHP script
    ... How do you put the folowing code into a php script that will create the ... database and then the Tables? ... (query by query, table by table) ... PRIMARY KEY ...
    (comp.lang.php)
  • Re: Basic PHP question...
    ... >> Here is my database details: ... >> I ran this php script: ... //now we make the query which will ask the database for the course ...
    (alt.php)
  • Timeout Error
    ... I have a PHP script which queries much of a large database. ... it takes a minute (depending on the extent of the query). ...
    (comp.lang.php)
  • Valeries powerfully gaining
    ... off a database upon the morning is too marine for Roxanne to ... Nowadays, I'll justify the job. ... Where Bob's famous blue detects, Roxanne shoulds beside old-fashioned, ... Let's total round the giant tents, ...
    (sci.crypt)