Cant Connect To Database

admin

Administrator
Staff member
Hello,<br /><br />I am completely new to PHP and am trying to see if I can access any db on my site. I have tried just about every script featured on hotscripts.com but nothing will connect to any databases I have set up. Maybe I am COMPLETELY doing everything wrong but I am following the directions to the T and all I seem to get is errors or it will just display the script in the browser.<br /><br />I am entering ("localhost", "user_user", "pass") into the script and then I just choose a database that the user is allowed to access.<br /><br />I am just wondering if I need something else to connect to a database.<br /><br />Sorry if this makes little sence since I have been fighting with it for 2 days now <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/blink.gif" style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> <br /><br />Thanks for any ideas!<!--content-->
Hi,<br /><br />Can you post a sample of the code here? Take out the password of course, and any other sensitive data, then we can have a look.<br /><br />I should look something like<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br />$host="localhost";<br />$db="usernm_dbname";<br />$user="username";<br />$passwd="password";<br /><br />$dbh=mysql_connect ($host, $user, $passwd) or die ('I cannot connect to the database because: ' . mysql_error());<br /><br />mysql_select_db ("$db");<br /><br />?><!--c2--></div><!--ec2--><br /><br />Andy<!--content-->
Hi,<br /><br />One of the scripts that I am trying out is ez_sql. A database tool from hotscripts.com.<br /><br />I get the following error:<br /><br />SQL/DB Error -- [<br />Error establishing a database connection!<br />Are you sure you have the correct user/password?<br />Are you sure that you have typed the correct hostname?<br />Are you sure that the database server is running?<br /><br />Here is a copy of the script where you make the changes for your server:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->CHANGE HERE<br /><br />    define("USER_USER", "");      // <-- mysql db user<br />    define("PASS", "");  // <-- mysql db password<br />    define("MYDB", "mysql");  // <-- mysql db pname<br />    define("EZSQL_DB_HOST", "localhost");    // <-- mysql server host<br /><br />    //<!--c2--></div><!--ec2--><br /><br />I leave everything just as it is except for USER_USER, PASS, and MYDB. <br /><br />The script says that this is the only area to modify.<br /><br />Thanks again, Thumbs Up <br /><br />srobbins<!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->define("MYDB", "mysql");  // <-- mysql db pname<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />I think they're looking for your database name.<br /><br />If you username in cpanel were "insignia" and you named your database "whatever" then you'd put <br /><br /> define("MYDB", "insignia_whatever"); // <-- mysql db pname<br /><br />When you go to Cpanel, and choose Manage Mysql, it should show you the name of your database. Also can be found in PHP myadmin.<!--content-->
Thanks surefire,<br /><br />I am specifying the db like you posted. I am wondering if it's a password problem.<br /><br />I am using <br /><br />HOST: "localhost"<br />USER: "user_user" -except my actual user (the one that I set up in cpanel)<br />PASS: "mypass" -except my actual pass (the one that I set up in cpanel)<br />DB: "trial"<br />I usually get error:<br /><br />1044: Access denied for user: 'user_user@localhost' to database 'trial'<br /><br />There must be something that I am not doing right????<br /><br />Thanks for the help so far Thumbs Up <br /><br />I'll keep trying<br /><br />Here is a copy of the script that I am currently playing with:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br /><br /><br />$connection = mysql_connect ("localhost", "user_user", "pass");<br />if ($connection == false){<br />  echo mysql_errno().": ".mysql_error()."<BR>";<br />  exit;<br />}   <br /><br />$query = "create table email_info " .<br />       "(fullname varchar(255), email_address varchar(255))";<br />$result = mysql_db_query ("trial", $query);<br /><br />if ($result)<br />  echo "Table 'email_info' was successfully created!";<br />else<br />  echo mysql_errno().": ".mysql_error()."<BR>";<br /><br />mysql_close ();<br /><br /><br />?> <br /><br /><br /><?php<br /><br />if ($submit == "click"){<br />  // The submit button was clicked!<br />  // Get the input for fullname and email then store it in the database.<br />  $connection = mysql_connect ("", "", "");<br />  if ($connection == false){<br />    echo mysql_errno().": ".mysql_error()."<BR>";<br />    exit;<br />  }   <br /><br />  $query = "insert into email_info values ('$fullname', '$email')";<br />  $result = mysql_db_query ("trial", $query);<br />  if ($result){<br />    echo "Success!";<br />  }<br />  else{<br />    echo mysql_errno().": ".mysql_error()."<BR>";<br />  }<br /><br />  mysql_close ();<br />}<br />else{<br />  echo "<br />    <html><body><br /><br />    <form method=\"post\" action=\"insert.php3\"><br /><br />    Enter your full name<br />    <input type=\"text\" name=\"fullname\"></input><br><br />    Enter your email address<br />    <input type=\"text\" name=\"email\"></input><br><br /><br />    <input type=\"submit\" name=\"submit\" value=\"click\"></input>        <br /><br />    </form><br /><br />    </body></html><br />  ";<br />}<br /><br />?><!--c2--></div><!--ec2--><br /><br /><br />I get a similar error no matter what script I use...<!--content-->
I got the above script to work......<br /><br /> <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/kicking.gif" style="vertical-align:middle" emoid=":dance:" border="0" alt="kicking.gif" /><!--content-->
If you named the db trial you should use username_trial for the db name. All databases and db users have the CPanel username appended to the front.<!--content-->
 
Top