HostGator.com » Support Portal

SQL errors

This is not an error you see in cPanel. This is the code you use to connect a php file to the database. (Be sure to replace the red parts with your actual information.)

Connection Strings
Perl $dbh = DBI->connect("DBI:mysql:cpuser_db:localhost","cpuser_dbuser","password");
PHP $dbh=mysql_connect ("localhost", "cpuser_dbuser", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cpuser_db");

Some real errors are as follows:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'someone'@'localhost' (using password: YES) in /home/cpusername/public_html/config.php on line 3
Couldn't connect to server.

This error tells you the exact situation. "Access denied" is your big clue! This means that the database user or password is incorrect in your php file. The database name must always be cpanelusername_databaseusername. You can check the correct spelling in cPanel, under MySQL Databases.


Parse error: syntax error, unexpected T_STRING in /home/cpusername/public_html/index.php on line 31

This error means you have made a mistake in your coding. Usually it is a missing punctuation, as PHP code is very sensitive. I apologize, but we cannot offer support for PHP coding mistakes.


Article Comments

Bill
What is the format of the database connection string for Chilisoft ASP?

HostGator
You will need to check the ASP documentation, but it should be similar to this:

<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=server; PORT=3306; DATABASE=database; USER=username; PASSWORD=password; OPTION=3;"
%>

mo
what is the php script to connect to mysql database?

thanks.

HostGator
That is what the "Connection Strings" are. The PHP one is

$dbh=mysql_connect ("localhost", "cpuser_dbuser", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("cpuser_db");

zonesny
FYI,
In Drupal (6), the connection string for the settings.php file is as follows:

$db_url = 'mysqli://cpuser_dbuser:password@localhost/cpuser_db';

In the url string, replace
cpuser_dbuser with your cpanel username + underscore + database username
password with your database password
cpuser_db with your cpanel username + underscore + database

Hope this is helpful for someone.

HostGator
Thank you for your comments. Just a quick reminder that the comments on this page are not monitored by technical support staff, and that for support issues, it is best to contact us by live chat, phone or email so we can assist you right away.

Although comments are not monitored by technical support staff, they are moderated and read by technical writers. Comments will need to be approved by a moderator before appearing.

Our technical writers do read the comments periodically for the purposes of updating the articles, and do appreciate your feedback, suggestions and corrections to the articles themselves, as well as any suggestions or tips for readers of this article. However, support questions posted here are not guaranteed to be replied to in a timely manner or at all. For support issues, it is best to contact our support staff instead by live chat, email or phone.



Your comments help us keep the knowledge base updated. This is not a medium for support. If you have questions or need help, please contact us via email, phone or live chat for fast assistance.

Post Comment