Jump to content


Photo

Creating a db connection


  • Please log in to reply
1 reply to this topic

#1 TomJ

TomJ
  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationHoogland, the Netherlands

Posted 08 May 2005 - 12:18 PM

Hello

In DWMX 61, I am trying to establish a connection with my MySQL database.
I had DW create it for me, and when DW checks it, it reports a working connection.
However, when I want to use that connection in a script, the string that represents the connection is rendered as "Resource Id #1". Consecutive uses of the connection variable will increase the reported ID number.

This is the code in the DW connector:
::::::::::::::::::::::::::::::::::::
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connAldfaer = "localhost";
$database_connAldfaer = "aldfaer_db";
$username_connAldfaer = "MyUsername";
$password_connAldfaer = "MyPassword";
$connAldfaer = mysql_pconnect($hostname_connAldfaer, $username_connAldfaer, $password_connAldfaer) or die(mysql_error());

echo '$hostname_connAldfaer: '. $hostname_connAldfaer.'<br>';
echo '$database_connAldfaer: '. $database_connAldfaer.'<br>';
echo '$username_connAldfaer: '. $username_connAldfaer.'<br>';
echo '$password_connAldfaer: '. $password_connAldfaer.'<br>';
echo '$connAldfaer: '.$connAldfaer;
?>
::::::::::::::::::::::::::::::::::::
When viewed in a browser, it says:
:::::::::::::::::::::::::::::::::::::
$hostname_connAldfaer: localhost
$database_connAldfaer: aldfaer_db
$username_connAldfaer: MyUsername
$password_connAldfaer: MyPassword
$connAldfaer: Resource id #2
:::::::::::::::::::::::::::::::::::::

I am sure I have overlooked a very simple thing, but I cannot figure out what. Afterall, I am a beginner in PHP.

Anyone a suggestion?

-t-
Tom Jacobs
[!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--][!--coloro:#D20000--][span style="color:#D20000"][!--/coloro--]
---------------------
-t- ยท Tom Jacobs
---------------------
[!--colorc--][/span][!--/colorc--][!--sizec--][/span][!--/sizec--]

#2 Guest_3nigma_*

Guest_3nigma_*
  • Guests

Posted 09 May 2005 - 07:16 AM

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php
$host [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\'localhost\'[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]$username [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\'your_username\'[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]$password [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\'your_password\'[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]$db_name [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\'your_db\'[/span][span style=\"color:#007700\"];

[/span][span style=\"color:#0000BB\"]$connect [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_connect[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\'$host\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'$username\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\'$password\'[/span][span style=\"color:#007700\"])
or die([/span][span style=\"color:#DD0000\"]\'Could not connect\' [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());

[/span][span style=\"color:#0000BB\"]$db_connect [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_select_db[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\'$db_name\'[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$connect[/span][span style=\"color:#007700\"])
or die([/span][span style=\"color:#DD0000\"]\'Could not select database\' [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());
[/span][span style=\"color:#0000BB\"]?>[/span]
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

Use that instead of the code DW has supplied you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users