247earnings Posted September 24, 2007 Share Posted September 24, 2007 Hi, I know very little about PHP. I am trying to install a PHP script on my server and get the following error message. I replaced username, directory, and folder name for security reasons. --------------------------------------------------------------------------- Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nobody'@'localhost' (using password: NO) in /bhome/username/directory/directory name/includes/functions/database.php on line 12 Unable to connect to database server! ------------------------------------------------------------------------- Here is the DB Privileges. I subbed the personal data. ------------------------------------------------------------------------- username_dbase name Users in dbase username_database name (NOTE:only first 8 characters of DB name) (Privileges: ALL PRIVILEGES) Connection Strings Perl $dbh = DBI->connect("DBI:mysql:username_DB Name:localhost","username_DB (1st ","<PASSWORD HERE>"); PHP $dbh=mysql_connect ("localhost", "username_DB name (first ", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("username_DBname"); -------------------------------------------------------------------------- Finally, here is the script for database.php in case you need it. -------------------------------------------------------------------- <?php /* */ function tep_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') { global $$link; if (USE_PCONNECT == 'true') { $$link = mysql_pconnect($server, $username, $password); } else { $$link = mysql_connect($server, $username, $password); } if ($$link) mysql_select_db($database); return $$link; } function tep_db_close($link = 'db_link') { global $$link; return mysql_close($$link); } function tep_db_error($query, $errno, $error) { die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000">[TEP STOP]</font></small><br><br></b></font>'); } function tep_db_query($query, $link = 'db_link') { global $$link; if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } $result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error()); if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) { $result_error = mysql_error(); error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG); } return $result; } function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') { reset($data); if ($action == 'insert') { $query = 'insert into ' . $table . ' ('; while (list($columns, ) = each($data)) { $query .= $columns . ', '; } $query = substr($query, 0, -2) . ') values ('; reset($data); while (list(, $value) = each($data)) { switch ((string)$value) { case 'now()': $query .= 'now(), '; break; case 'null': $query .= 'null, '; break; default: $query .= '\'' . tep_db_input($value) . '\', '; break; } } $query = substr($query, 0, -2) . ')'; } elseif ($action == 'update') { $query = 'update ' . $table . ' set '; while (list($columns, $value) = each($data)) { switch ((string)$value) { case 'now()': $query .= $columns . ' = now(), '; break; case 'null': $query .= $columns .= ' = null, '; break; default: $query .= $columns . ' = \'' . tep_db_input($value) . '\', '; break; } } $query = substr($query, 0, -2) . ' where ' . $parameters; } return tep_db_query($query, $link); } function tep_db_fetch_array($db_query) { return mysql_fetch_array($db_query, MYSQL_ASSOC); } function tep_db_num_rows($db_query) { return mysql_num_rows($db_query); } function tep_db_data_seek($db_query, $row_number) { return mysql_data_seek($db_query, $row_number); } function tep_db_insert_id() { return mysql_insert_id(); } function tep_db_free_result($db_query) { return mysql_free_result($db_query); } function tep_db_fetch_fields($db_query) { return mysql_fetch_field($db_query); } function tep_db_output($string) { return htmlspecialchars($string); } function tep_db_input($string) { return addslashes($string); } function tep_db_prepare_input($string) { if (is_string($string)) { return trim(tep_sanitize_string(stripslashes($string))); } elseif (is_array($string)) { reset($string); while (list($key, $value) = each($string)) { $string[$key] = tep_db_prepare_input($value); } return $string; } else { return $string; } } ?> --------------------------------------------------------------------------- Thanks for any help you can provide. Rudy Link to comment https://forums.phpfreaks.com/topic/70478-unable-to-connect-to-database-server/ Share on other sites More sharing options...
Fadion Posted September 24, 2007 Share Posted September 24, 2007 Are u sure ure passing the right parameters to mysql_connect, meaning the right user and pass? Do u have a user 'nobody'? If so grant him privileges via phpmyadmin or by sql console. Link to comment https://forums.phpfreaks.com/topic/70478-unable-to-connect-to-database-server/#findComment-354095 Share on other sites More sharing options...
247earnings Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks for your quick reply. No, I am not sure on anything dealing with PHP. I added "nobody" as a username and gave it full privileges. I now have 3 users associated with this database. All have full privileges. When I saved the "nobody" username as well as the other two, the script inserted my Control Panel username in front of it. e.g. username_nobody. I hope this helps. Rudy Link to comment https://forums.phpfreaks.com/topic/70478-unable-to-connect-to-database-server/#findComment-354207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.