Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,685 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,248 people online right now. Registration is fast and FREE... Join Now!




mysql connection problem

 
Reply to this topicStart new topic

mysql connection problem

jorrigal
post 24 May, 2008 - 11:59 PM
Post #1


New D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 25



Dream Kudos: 50
My Contributions


i am not able to connect to the database.
my code is

CODE

<?php
echo " hai 1 ";

$db=mysql_connect("localhost","root","football");
if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }


echo "hai 2";

?>


The correct output is hai 1 followed by hai 2, but it is showing only hai 1.

and it is not displaying any error too.

is the default user name is "root"?

i am using mysql 5.0.51b

User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 25 May, 2008 - 12:48 AM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


Can you connect to the database outside of php? Like from a command prompt or database admin program? Can you verify that mysql is running?
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 25 May, 2008 - 01:07 AM
Post #3


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


Hod did you install and configure PHP/Apache/MySQL ?
Are you sure if MySQL is up and running ?
User is offlineProfile CardPM

Go to the top of the page

jorrigal
post 25 May, 2008 - 01:27 PM
Post #4


New D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 25



Dream Kudos: 50
My Contributions


QUOTE(no2pencil @ 25 May, 2008 - 01:48 AM) *

Can you connect to the database outside of php? Like from a command prompt or database admin program? Can you verify that mysql is running?


yes i can connect to the database from command prompt.
User is offlineProfile CardPM

Go to the top of the page

jorrigal
post 25 May, 2008 - 01:48 PM
Post #5


New D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 25



Dream Kudos: 50
My Contributions


QUOTE(MitkOK @ 25 May, 2008 - 02:07 AM) *

Hod did you install and configure PHP/Apache/MySQL ?
Are you sure if MySQL is up and running ?


i download and installed PHP/Apache/MySQL software according to the guidance given by this site.

http://www.sebastiansulinski.co.uk/web_des...e.php?id=mysql#


and how come i know that MySQL is up or down.
User is offlineProfile CardPM

Go to the top of the page

mindstorms6
post 26 May, 2008 - 06:22 PM
Post #6


New D.I.C Head

*
Joined: 25 May, 2008
Posts: 5

have you tried connecting through something like mysql administrator.... or query browser....

and for fun, try this instead....

and yes, also the @ isn't necessary. but i don't like my users seeing error messages beside the monkey thing....

CODE

$dbcnx = @mysql_connect("localhost", "root", "football") or die("This can't be good. Darn those monkeys");
mysql_select_db("dbname", $dbcnx);



and if you're running this on your local computer you can see if the MySQL service is running, in services.msc...

This post has been edited by mindstorms6: 26 May, 2008 - 06:26 PM
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 27 May, 2008 - 05:50 AM
Post #7


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600

Expert In: PHP, Web Security

My Contributions


Guys, he should be getting an error message from die() if there was a problem connecting.

My assumption is your mysql driver is not loaded.

try this

CODE

<?php phpinfo(); ?>


And see if mysql is there.

Also to easily troubleshoot errors, turn on display_errors in your httpd.conf , I'm thinking it will say something like function not found mysql_connect or something.


Actually to test my theory, put the following in a file and see what it says:
CODE

<?php
function_exists('mysql_connect') ? $e='exists':$e='does not exist';
echo $e;


This post has been edited by joeyadms: 27 May, 2008 - 05:55 AM
User is offlineProfile CardPM

Go to the top of the page

clargs
post 27 May, 2008 - 05:58 AM
Post #8


New D.I.C Head

*
Joined: 17 May, 2008
Posts: 20


My Contributions


joeyadms is right,
PHP calls the mysql functions from the mysql module.

Try re-installing PHP again and make sure you have checked the MYSQL checkbox.

As joeyadms says. if the mysql module is not installed, your code will exit immediately without giving any error messages.

Happy Coding, smile.gif
clargs
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:01AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month