You are here: Storing database resource links « PHP Programming Language « IT news, forums, messages
Storing database resource links

Posted by Ney Andrι de Mello Zunino on 12/16/19 11:57

Hello.

Could anyone explain to me why the following code fails?

// =====Begin sample code=====

global $blog;

define("dbHost", "localhost");
define("dbUser", "ney");
define("dbPassword", "xxx");
define("dbDatabase", "blog");

function dbConnect()
{
// Stores the database resource link in the global array
$blog["db"] = mysql_connect(constant("dbHost"),
constant("dbUser"),
constant("dbPassword"))
or die("DB connection error: " . mysql_error());
mysql_select_db('blog')
or die("Error selecting blog database: " . mysql_error());
}

function dbDisconnect()
{
// Closes the connection represented by the resource link stored
// in the global array
mysql_close($blog["db"]);
}

dbConnect();
..
..
..
dbDisconnect();

// =====End sample code=====

Upon runtime, PHP produces the following warning:

Warning: mysql_close(): supplied argument is not a valid MySQL-Link
resource in /home/ney/Blog/db.php on line 22

I would appreciate if anyone could point out my mistake and kindly
explain the situation.

Thank you.

--
Ney AndrΓ© de Mello Zunino

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация