Killersites.com Homepage Welcome Guest   |   Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | User List  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 3
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 1395 times and has 2 replies Next Thread
Male duframe
Newbie




Joined: Nov 28, 2006
Post Count: 30
Status: Offline
Reply to this Post  Reply with Quote 
connecting php to mysql?

i am trying just to connect to my database. this is my first time and i seem to be following all that i read correctly. but that can't be the case since i am not connecting. anyway, this is the code that i am using.

<?php
$me = "myUserID";
$pass = "myPassword";
$host = "mysqladmin2.secureserver.net";

mysql_connect($host, $me, $pass);

@mysql_select_db('myDatabaseName) or die( "Error! Unable to connect.");

mysql_close();

?>

i also have a port number to connect to. i've tried using localhost in place of $host:
mysql_connect(localhost, $me, $pass);

I just can't connect. Please help!
Thanks

[Dec 2, 2006 1:27:53 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male Zero
Advanced Member
Member's Avatar


Joined: Aug 23, 2005
Post Count: 101
Status: Offline
Reply to this Post  Reply with Quote 
Re: connecting php to mysql?

Hi Duframe,

first of all change:
mysql_connect($host, $me, $pass);
to
mysql_connect($host, $me, $pass) or die ( "Unable to connect to database");

This to specifie where the problem is.

$host has to be either localhost or a ip number. check your mysql admin or "hosting cpanel" to look for your ip.

Kind regards,

Zero
[Dec 4, 2006 3:17:39 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male admin
Advanced Member
Member's Avatar


Joined: Jun 14, 2003
Post Count: 2940
Status: Offline
Reply to this Post  Reply with Quote 
Re: connecting php to mysql?

Here it is a little more complete:


$dbh = mysql_connect ("localhost", "killerphp", "<PASSWORD HERE>")or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("killerphp");

...

Note that I am using the function: mysql_error(), to find out what the error was.

CIAO

Stefan
----------------------------------------
Stefan Mischook

Video Tutorial Store | Web Templates
----------------------------------------
[Edit 1 times, last edit by admin at Dec 4, 2006 9:16:04 AM]
[Dec 4, 2006 9:15:36 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread