GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Mar-2007, 10:16
pembomassive pembomassive is offline
New Member
 
Join Date: Mar 2007
Posts: 11
pembomassive is on a distinguished road
Exclamation

mysql connect (error)


Hi , i'm trying to connect php to the db using the following code (the name of my db is called multiple choice), it is in a wamp server an there is no password or user name

PHP Code:

<?php
$con = mysql_connect("localhost");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }if (mysql_query("CREATE DATABASE multiple choice",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();


I get the following error message, anyone know why?:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\connect\connect.php on line 2
Could not connect: Access denied for user 'ODBC'@'localhost' (using password: NO)


}mysql_close($con);
?>
Last edited by LuciWiz : 08-Mar-2007 at 12:26. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 08-Mar-2007, 12:09
davethedork davethedork is offline
New Member
 
Join Date: Mar 2007
Posts: 11
davethedork is on a distinguished road

Re: mysql connect (error)


To connect to the database you have to have pass the hostname, username, and password.

From php.net/mysql_connect

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
__________________
davethedork
unix/linux systems administrator
http://tvghosting.com :: Top Notch Servers + Excellect Support
  #3  
Old 08-Mar-2007, 12:39
pembomassive pembomassive is offline
New Member
 
Join Date: Mar 2007
Posts: 11
pembomassive is on a distinguished road

Re: mysql connect (error)


When I go into my DB I don't have a username and password though?
  #4  
Old 08-Mar-2007, 13:29
davethedork davethedork is offline
New Member
 
Join Date: Mar 2007
Posts: 11
davethedork is on a distinguished road

Re: mysql connect (error)


To connect to mysql you must supply at least a username and it would smart of you to assign that user a password.
__________________
davethedork
unix/linux systems administrator
http://tvghosting.com :: Top Notch Servers + Excellect Support
  #5  
Old 05-Apr-2007, 14:49
lwbbs lwbbs is offline
New Member
 
Join Date: Apr 2007
Location: www.easywebx.com
Posts: 27
lwbbs has a little shameless behaviour in the past

Re: mysql connect (error)


use root as user name

Quote:
Originally Posted by pembomassive
Hi , i'm trying to connect php to the db using the following code (the name of my db is called multiple choice), it is in a wamp server an there is no password or user name

PHP Code:

<?php
$con = mysql_connect("localhost");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }if (mysql_query("CREATE DATABASE multiple choice",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();


I get the following error message, anyone know why?:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\wamp\www\connect\connect.php on line 2
Could not connect: Access denied for user 'ODBC'@'localhost' (using password: NO)


}mysql_close($con);
?>
  #6  
Old 05-Apr-2007, 16:32
davethedork davethedork is offline
New Member
 
Join Date: Mar 2007
Posts: 11
davethedork is on a distinguished road

Re: mysql connect (error)


Quote:
use root as user name

BAD idea.

Create a new user to use the db.

mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
__________________
davethedork
unix/linux systems administrator
http://tvghosting.com :: Top Notch Servers + Excellect Support
  #7  
Old 06-Apr-2007, 15:04
lwbbs lwbbs is offline
New Member
 
Join Date: Apr 2007
Location: www.easywebx.com
Posts: 27
lwbbs has a little shameless behaviour in the past

Re: mysql connect (error)


Of course, it is a good idea to create a new user.
But I just want to tell pembomassive can user root as a user name.
It is a easy way to test code in local.

Quote:
Originally Posted by davethedork
BAD idea.

Create a new user to use the db.

mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 10:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30
What is "Ambigious symbol" ??*( a compilation error) small_ticket CPP / C++ Forum 2 07-Jan-2005 21:10
Can enum have same name as class? crystalattice CPP / C++ Forum 3 08-Dec-2004 16:43

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:54.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.