database

This is a discussion on database within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm very new with php, so perhaps it's a silly question. I want a connection with a ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-27-2003
Alain Dhaene
 
Posts: n/a
Default database

Hi,

I'm very new with php, so perhaps it's a silly question.

I want a connection with a mysql database.
This works. I can open, retrieve data, and close the database.

But this happens in the same page.

Now I want one page that has a function who's opening and close the
connection. In another page I want include this page. But I don't know the
syntax.

e.g

page connectie.php

Function openDB()
{
$link = mysql_connect("localhost", "host", "pas")

or die("geen connectie mogelijk : " . mysql_error());
print "connectie ok";
mysql_select_db("database") or die("geen database gevonden");

}

Function closeDB()
{
mysql_close($link);
}
End Function
?>

<?php

page input.php

include ('connectie.php');

//open connectie

$connectie = openDB();

//code

//close connectie
$connectie = closeDB();



This gives an error when I want to close the db. In the function I said
close($link) but of course he cann't see this variabel. How can I fix that?

Alain D'Haene

Or is it possible the set the connection in an Object, and use this object
during the Session?
Reply With Quote
  #2 (permalink)  
Old 10-27-2003
Jordan S. Jones
 
Posts: n/a
Default Re: [PHP] database

Alain,

You can pass it in the function as a variable.

E.g...

Function closeDB($ref_link)
{
mysql_close($ref_link);
}


closeDB($connectie);

Hope this Helps,

Jordan S. Jones

--

I am nothing but a poor boy. Please Donate..
https://www.paypal.com/xclick/busine...rency_code=USD
Reply With Quote
  #3 (permalink)  
Old 10-27-2003
Alain Dhaene
 
Posts: n/a
Default Re: [PHP] database

I have try
but I get the following error:


Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource
in /home/schoolre/public_html/Hitek/Online/connectie.php on line 16

Alain


"Jordan S. Jones" <list@racistnames.com> schreef in bericht
news:3F9D61F5.7040105@racistnames.com...
> Alain,
>
> You can pass it in the function as a variable.
>
> E.g...
>
> Function closeDB($ref_link)
> {
> mysql_close($ref_link);
> }
>
>
> closeDB($connectie);
>
> Hope this Helps,
>
> Jordan S. Jones
>
> --
>
> I am nothing but a poor boy. Please Donate..
>

https://www.paypal.com/xclick/busine...item_name=Jord
an+S.+Jones&no_note=1&tax=0&currency_code=USD
Reply With Quote
  #4 (permalink)  
Old 10-27-2003
Jordan S. Jones
 
Posts: n/a
Default Re: [PHP] database

Alain,

Ok, I aplogize, for I neglected to notice that you were not passing back
the db connection $link variable from your openDB function, so here is
what you are going to want to do.

page connectie.php

Function openDB()
{
$link = mysql_connect("localhost", "host", "pas")

or die("geen connectie mogelijk : " . mysql_error());
print "connectie ok";
mysql_select_db("database") or die("geen database gevonden");
return $link;
}

Function closeDB($ref_link)
{
mysql_close($ref_link);
}


include ('connectie.php');

//open connectie

$connectie = openDB();

//code

//close connectie
closeDB($connectie);




Jordan S. Jones


alain dhaene wrote:

>I have try
>but I get the following error:
>
>
>Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource
>in /home/schoolre/public_html/Hitek/Online/connectie.php on line 16
>
>Alain
>
>
>"Jordan S. Jones" <list@racistnames.com> schreef in bericht
>news:3F9D61F5.7040105@racistnames.com...
>
>
>>Alain,
>>
>>You can pass it in the function as a variable.
>>
>>E.g...
>>
>>Function closeDB($ref_link)
>>{
>> mysql_close($ref_link);
>>}
>>
>>
>>closeDB($connectie);
>>
>>Hope this Helps,
>>
>>Jordan S. Jones
>>
>>--
>>
>>I am nothing but a poor boy. Please Donate..
>>
>>
>>

>https://www.paypal.com/xclick/busine...item_name=Jord
>an+S.+Jones&no_note=1&tax=0&currency_code=USD
>
>
>


--
I am nothing but a poor boy. Please Donate..
https://www.paypal.com/xclick/busine...rency_code=USD
Reply With Quote
  #5 (permalink)  
Old 10-28-2003
John Nichel
 
Posts: n/a
Default Re: [PHP] database

alain dhaene wrote:
> I have try
> but I get the following error:
>
>
> Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource
> in /home/schoolre/public_html/Hitek/Online/connectie.php on line 16
>
> Alain

<snip>

Look here....

http://us4.php.net/manual/en/languag...bles.scope.php

Your $link only has the scope of that function. You can either pass it
to the function, or put this line inside of your function....

global $link;

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
Reply With Quote
  #6 (permalink)  
Old 10-28-2003
Alain Dhaene
 
Posts: n/a
Default Re: [PHP] database

It works,

Thx
"John Nichel" <jnichel@by-tor.com> schreef in bericht
news:3F9DBBDE.9020502@by-tor.com...
> alain dhaene wrote:
> > I have try
> > but I get the following error:
> >
> >
> > Warning: mysql_close(): supplied argument is not a valid MySQL-Link

resource
> > in /home/schoolre/public_html/Hitek/Online/connectie.php on line 16
> >
> > Alain

> <snip>
>
> Look here....
>
> http://us4.php.net/manual/en/languag...bles.scope.php
>
> Your $link only has the scope of that function. You can either pass it
> to the function, or put this line inside of your function....
>
> global $link;
>
> --
> By-Tor.com
> It's all about the Rush
> http://www.by-tor.com

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:48 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0