Reply
connecting to mysql database
Old 08-06-2008, 08:09 PM connecting to mysql database
Average Talker

Posts: 29
Trades: 0
i want to connect to my database but i don't know how to set the username and the password to the database in order for my connection to be successful.i have EasyPhp installed on my computer which is another way to get php,mysql and apache installed on your computer. any one with an idea?
please help.
kani alavi is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 08-07-2008, 03:05 AM Re: connecting to mysql database
Lashtal's Avatar
PHP Learner

Posts: 492
Name: Lashtal
Trades: 0
First off: Do you know the name of your Database and it's Server Address (typically "localhost"), or the password to your Database?

If you do, insert these values into the following script:

Code:
<?php
$dbhost = 'EDIT';
$dbuser = 'EDIT';
$dbpass = 'EDIT';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'EDIT';
mysql_select_db($dbname);
?>

If you get your username/password/database fields correct, you should be connected now

If not, you will see the dreaded error
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 08-07-2008, 08:38 AM Re: connecting to mysql database
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
I'd just make these changes to Lashtal's code so that you can have a bit more informative error message:
PHP Code:
<?php
$dbhost 
'EDIT';
$dbuser 'EDIT';
$dbpass 'EDIT';
$dbname 'EDIT';

if (
$conn mysql_connect($dbhost$dbuser$dbpass)) {
  if (!
mysql_select_db($dbname)) {
    echo 
'<p>Unable to connect to the database.  MySQL said &quot;'.mysql_error().'&quot;</p>';
  }
} else {
  echo 
'<p>Unable to connect to the database server.  MySQL said &quot;'.mysql_error().'&quot;</p>';
}
?>
__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 08-08-2008, 03:29 AM Re: connecting to mysql database
Lashtal's Avatar
PHP Learner

Posts: 492
Name: Lashtal
Trades: 0
Very important to include when you're starting out

Helps to have that error or success message show up.
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 08-09-2008, 07:56 PM Re: connecting to mysql database
Average Talker

Posts: 29
Trades: 0
thanks for the all the good answers. but i only know of the database name and the server address(localhost) .i don't know of the username and the password. how do i create them or set them because i did not set or create them when i was creating the database?
kani alavi is offline
Reply With Quote
View Public Profile
 
Old 08-09-2008, 08:04 PM Re: connecting to mysql database
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
Do you have a control panel like cPanel or Plesk? If so, they will allow you to create a user and password -- just remember to assign the user to the database or you won't be able to access the database with that user and password.

If you're executing the SQL directly and have the right privileges, then you can use this syntax:

Code:
grant all privileges on dbname.* to 'username'@localhost identified by 'password'
__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to connecting to mysql database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.15079 seconds with 13 queries