Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 54
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
 
 
Register now for full access!
Old 08-07-2008, 03:05 AM Re: connecting to mysql database
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 679
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
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 08-07-2008, 08:38 AM Re: connecting to mysql database
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
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

Please login or register to view this content. Registration is FREE
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
wherenomanhasgonebefore

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

Helps to have that error or success message show up.
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 08-09-2008, 07:56 PM Re: connecting to mysql database
Skilled Talker

Posts: 54
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
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
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

Please login or register to view this content. Registration is FREE
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.19785 seconds with 12 queries