Jump to content


Photo

Database connectivity


  • Please log in to reply
1 reply to this topic

#1 gracecodesign

gracecodesign
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 November 2005 - 08:43 PM

This is probably so simple but I am really new to MySQL and PHP.
Are there any backend preferences or settings to think about?
Help!


error message ::

Access denied for user: 'gracecod_simple@localhost' to database 'gracecod_simpleauth'

php script ::

<?php
error_reporting(E_ALL);
include_once("functions.php");
session_register("login");
session_register("password");
session_register("loggedIn");

$messages=array();

$dbhost="localhost:8080";
$dbuser="gracecod_simple";
$dbpass="*";
$dbname="gracecod_simpleauth";

$conn = connectToDB($dbhost,$dbuser,$dbpass,$dbname);

function connectToDB($dbhost,$dbuser,$dbpass,$dbname) {
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($dbname,$conn) or die(mysql_error());
return $conn;
}
?>

thanks so much


#2 MxpUnk

MxpUnk
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 04 December 2005 - 03:07 PM

[!--quoteo(post=319252:date=Nov 16 2005, 03:43 PM:name=GraceandCo)--][div class=\'quotetop\']QUOTE(GraceandCo @ Nov 16 2005, 03:43 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]




Access denied for user: 'gracecod_simple@localhost' to database 'gracecod_simpleauth' [/quote]


The obove error is just a connecting to the database error. It's simple to fix. 1. You can edit the below code to match you're database.

$conn = connectToDB($dbhost,$dbuser,$dbpass,$dbname);

function connectToDB($dbhost,$dbuser,$dbpass,$dbname) {
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($dbname,$conn) or die(mysql_error());
return $conn;


Also, if you already have a connect.php file for your site, that is correct, you can do
<?php include('connect.php'); ?>

That does the same thing as you had, so. :) If you don't have a connect.php file, I would make one..

<?php
ob_start();
@mysql_connect("localhost","db_name","password") or    die('
   <link href=style.css rel=stylesheet>

   <Br>

    Down

   <br>

   

   Could not connect; ' . mysql_error());

mysql_select_db("db_name");
?>

The above is how I make my connect.php, there are some other ways.. But like I said if you dont have connect, you might want it :)





Also:
$dbhost="localhost:8080";
$dbuser="gracecod_simple";
$dbpass="*";
$dbname="gracecod_simpleauth";

Just checking, but the $dbname you're connecting too could be wrong too. :P


Well anyway, I tried to explain this in simplist form, and as I said it's VERY simple to overcome. Just change the db names around, and connect, and you've got it! :)



[!--quoteo(post=319252:date=Nov 16 2005, 03:43 PM:name=GraceandCo)--][div class=\'quotetop\']QUOTE(GraceandCo @ Nov 16 2005, 03:43 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]




Access denied for user: 'gracecod_simple@localhost' to database 'gracecod_simpleauth' [/quote]


The obove error is just a connecting to the database error. It's simple to fix. 1. You can edit the below code to match you're database.

$conn = connectToDB($dbhost,$dbuser,$dbpass,$dbname);

function connectToDB($dbhost,$dbuser,$dbpass,$dbname) {
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($dbname,$conn) or die(mysql_error());
return $conn;


Also, if you already have a connect.php file for your site, that is correct, you can do
<?php include('connect.php'); ?>

That does the same thing as you had, so. :) If you don't have a connect.php file, I would make one..

<?php
ob_start();
@mysql_connect("localhost","db_name","password") or    die('
   <link href=style.css rel=stylesheet>

   <Br>

    Down

   <br>

   

   Could not connect; ' . mysql_error());

mysql_select_db("db_name");
?>

The above is how I make my connect.php, there are some other ways.. But like I said if you dont have connect, you might want it :)





Also:
$dbhost="localhost:8080";
$dbuser="gracecod_simple";
$dbpass="*";
$dbname="gracecod_simpleauth";

Just checking, but the $dbname you're connecting too could be wrong too. :P


Well anyway, I tried to explain this in simplist form, and as I said it's VERY simple to vercome. Just change the db names around, and connect, and you've got it! :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users