Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

mysql_connect doesn't seem to work


  • Please log in to reply
9 replies to this topic

#1 ayush

ayush

  • Members
  • 19 posts
  • OFFLINE
  •  
  • Local time:01:26 PM

Posted 27 February 2011 - 08:22 PM

i was trying to join mysql with my php page....
for that i used
$sdbc=if(mysql_connect('localhost',myusername,mypassword));
{
echo "databse selected";
}
else {
echo "error connecting to database".mysql_error();
}

quite simple and typical code...but the problem is that connection doesn't occur...

can any one tell me what could be the possible problems...

i've hear this kind of problem used to come in vista..but i am using ubuntu 10.10...so why i am getting this error....

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:56 AM

Posted 28 February 2011 - 06:57 AM

There are tons of things that could be wrong, MySql may not be running. It may not be running on the default port. You may be suing the wrong password or user name. You may have not granted the proper access rights to your user in the database, etc.

Plus your code is not correct. Try this instead:
if(mysql_connect('localhost',myusername,mypassword))
{
echo "databse selected";
}
else {
echo "error connecting to database".mysql_error();
}

Edited by groovicus, 28 February 2011 - 06:58 AM.


#3 ayush

ayush
  • Topic Starter

  • Members
  • 19 posts
  • OFFLINE
  •  
  • Local time:01:26 PM

Posted 28 February 2011 - 11:03 AM

well mysql is running..
i tried it using terminal window and mysql is working perfectly fine..
username and password are correct...
i don't know how to know about whether mysql is running on correct port or not..if this is the problem then how can i rectify it

moreover if this too isn't a problem then what can be the solution....will removing the mysql package solve the problem???

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:56 AM

Posted 28 February 2011 - 01:14 PM

Did you read the second part of my post? <_<

#5 ayush

ayush
  • Topic Starter

  • Members
  • 19 posts
  • OFFLINE
  •  
  • Local time:01:26 PM

Posted 28 February 2011 - 01:40 PM

ohhh...sorry sorry
i hadn't seen what i was coding....actually i was writing a different code and then changed my mind....actually i coded what you wrote only in my php file and it didn't work....

any suggestions????

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:56 AM

Posted 28 February 2011 - 02:01 PM

When you say that the user name and password are correct, do you mean that you can actually login to mysql with them using the command line?

If you have not changed any of the default settings for MySql, then that shouldn't be a problem.

What do you mean by "is that connection doesn't occur." Is it displaying your error message? Are you running the php file from the command line or using a web server?

#7 ayush

ayush
  • Topic Starter

  • Members
  • 19 posts
  • OFFLINE
  •  
  • Local time:01:26 PM

Posted 28 February 2011 - 02:15 PM

yes i can actually login using them using the command line

Server error
The website encountered an error while retrieving http://localhost/jh.php. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this web page later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

as you can see the....even the code isn't being executed......

does it has anything to do with the root account of my ubuntu...you know regarding the permissions and all....

#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:56 AM

Posted 28 February 2011 - 02:56 PM

I don't think your web server is running. Try running this from the command line:
ps ax | grep httpd

You should see some entries similar to this:
1000 ?? Ss 0:54.46 /usr/local/sbin/httpd -f /usr/marina/etc/apache/httpd.conf

If not, you need to start it. Just an FYI, it would really be helpful when you have a problem to include any error messages. Had I know, I wouldn't have bothered with my other suggestions since they are not relevant.

#9 ayush

ayush
  • Topic Starter

  • Members
  • 19 posts
  • OFFLINE
  •  
  • Local time:01:26 PM

Posted 28 February 2011 - 04:35 PM

i tried the command and here is the output..

25499 pts/0 T 0:00 grep --color=auto httpd
25930 pts/0 S+ 0:00 grep --color=auto httpd
from the output i don't think that apache is running...
i tried restarting it using /etc/init.d/apache2 restart....it shows ok.. but when i again use the same command nothing happens

#10 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:01:56 AM

Posted 28 February 2011 - 09:12 PM

THen you need ot figure out why it isn't running. Apache has a god website with lots of support and documentation.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users