If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Could not connect:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-09-10, 05:42
nadeem14375 nadeem14375 is offline
Registered User
 
Join Date: Oct 2010
Posts: 3
Could not connect:

Dear all,

me new to PHP/ MySql.

I have the following code:

<?php
$con = mysql_connect("localhost","my_db","") or die('Could not connect: ' . mysql_error());
/*
// create Database
$qResult = mysql_query("CREATE DATABASE my_db",$con) or die('Database created...... '.mysql_error());
// echo "Database created";
*/
// Create table
mysql_select_db("my_db", $con) or die ("MySQL crapped out with:".MySQLErrNo()." ~ ".MySQLError);

$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";

// Execute query
$qResult = mysql_query($sql,$con) or die ("Failed to create table: ".MySQLErrNo()." ~ ".MySQLError);

mysql_close($con);
?>

it gives the following error:

Could not connect: Access denied for user 'my_db'@'localhost' (using password: NO)

How to know the password of my database?

What willl be the default password for root?

Regards:

Muhammad Nadeem
Reply With Quote
  #2 (permalink)  
Old 10-09-10, 11:51
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
look at the manual for MySQL permissions
its never a smart idea to run PHP scripts with the userid of 'root'
its never a smart idea to have a null password for any user, especially user 'root'

best thing to do in my books is to download the MySQL GUI tools which includes MySQL Administrator and MySQL Query Browser from the MySQL website. you can set permissions easily using the MySQL administrator program.

its also a useful way of knowing that basic things like userid's permissions and so on area ll working before tearing your hair out in a PHP or other script
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 10-11-10, 11:34
prestate101 prestate101 is offline
Registered User
 
Join Date: Oct 2010
Posts: 1
Thanks For The Idea

I am new to the php and thanks to you giving some tips that is useful and helpful. keep posting more tips thanks!!!!
Reply With Quote
  #4 (permalink)  
Old 11-01-10, 04:23
ypulse ypulse is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
suggestion

follow the advise above.. look it up in the manual for permissions..
and also, I would advise that you store the connection variables on a different file and just include it in. (it would be easier to change variable parameters later on)
If your the admin of that database, I would also suggest that you create a new user with passwords and grant it only with the permissions needed for that task.
Reply With Quote
Reply

Tags
mysql, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On