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-->
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-->