Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/2303-creating-a-db-connection/
Share on other sites

Guest 3nigma

[!--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.

Link to comment
https://forums.phpfreaks.com/topic/2303-creating-a-db-connection/#findComment-7562
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.