bmac Posted December 3, 2004 Posted December 3, 2004 I've written a small .php file that snags info from the DB and converts it into a CSV file. I uploaded the file into the main catalog directory, but whenever I try and run it (ie, I just type www.mystore.com/catalog/php_program.php) I get the following error: Access denied for user: 'brian_osc3@localhost' (Using password: YES) Here's the command I'm using to connect to the DB: <?php $result =mysql_connect ("localhost", "brian_osc3", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("brian_osc3"); Anybody have any ideas why this might not be working!? It's driving me crazy. Thanks all, Brian
Guest Posted December 3, 2004 Posted December 3, 2004 it may not be taking the straight db, password, etc, use $dbname, $dbuser, $dbpasswd as variables and then place inside your connect here is an example: <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_paw = "localhost"; $database_paw = "paw"; $username_paw = "paw"; $password_paw = "paw"; $paw = mysql_pconnect($hostname_paw, $username_paw, $password_paw) or trigger_error(mysql_error(),E_USER_ERROR); ?>
Jan Zonjee Posted December 3, 2004 Posted December 3, 2004 I believe the syntax to execute a query is usually something in the line of: $connection = mysql_connect($db_host, $db_user, $db_pass) or die('I cannot connect to the database because: ' . mysql_error()); $query = "SELECT COUNT(*) AS blah, blah"; mysql_select_db($db_name); $result = mysql_query($query, $connection) or die ("Error in query: $query. " . mysql_error());
bmac Posted December 3, 2004 Author Posted December 3, 2004 I tried this and the same problem stands (still unable to connect to the DB, access denied). Could this be some sort of permissions problem? Thanks for your help, Brian it may not be taking the straight db, password, etc, use $dbname, $dbuser, $dbpasswd as variables and then place inside your connect here is an example: <?php # FileName="Connection_php_mysql.htm" # Type="MYSQL" # HTTP="true" $hostname_paw = "localhost"; $database_paw = "paw"; $username_paw = "paw"; $password_paw = "paw"; $paw = mysql_pconnect($hostname_paw, $username_paw, $password_paw) or trigger_error(mysql_error(),E_USER_ERROR); ?> <{POST_SNAPBACK}>
Guest Posted December 3, 2004 Posted December 3, 2004 yes, have you tried from the prompt to connect? mysql -u username -p databasename and then you get prompted for a password. if you are doing this in a windows machine, you have to specify the path first, ie: \mysql\bin\mysql -u username -p databasename
bmac Posted December 3, 2004 Author Posted December 3, 2004 How do you do this from the internet? The file I'm trying to run is on a webserver and I don't know how to connect to the DB using the method below... yes, have you tried from the prompt to connect? mysql -u username -p databasename and then you get prompted for a password. if you are doing this in a windows machine, you have to specify the path first, ie: \mysql\bin\mysql -u username -p databasename <{POST_SNAPBACK}>
bmac Posted December 3, 2004 Author Posted December 3, 2004 To access the db otherwise, I use phpMyadmin. However, I'm trying to set up an automated .php process to pull info out of the DB for me without having to log into the db through phpMyadmin (hope that makes a bit of sense...). How do you do this from the internet? The file I'm trying to run is on a webserver and I don't know how to connect to the DB using the method below... <{POST_SNAPBACK}>
djenniex Posted December 3, 2004 Posted December 3, 2004 It sounds like you don't have permission set for brian_osc3 on the localhost. Either add another entry in the mysql user table for brian_osc3 for localhost, or change your script to point to the server $result =mysql_connect ("servername.com", "brian_osc3", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("brian_osc3");
bmac Posted December 3, 2004 Author Posted December 3, 2004 I agree. But, the brian_osc3 & corresponding password is information I've taken directly from the configure.php file-- so, it seems like if it can connect there, it should be able to connect elsewhere... thoughts? appreciate your help, brian It sounds like you don't have permission set for brian_osc3 on the localhost. Either add another entry in the mysql user table for brian_osc3 for localhost, or change your script to point to the server $result =mysql_connect ("servername.com", "brian_osc3", "******") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("brian_osc3"); <{POST_SNAPBACK}>
bmac Posted December 6, 2004 Author Posted December 6, 2004 Hey all, Just wondering if anyone else might have any ideas. I've triple checked the password & user name, the permissions on the username, etc. Still not able to connect tot he DB from a .php file. Any help, as always, is much appreciated. Brian I agree. But, the brian_osc3 & corresponding password is information I've taken directly from the configure.php file-- so, it seems like if it can connect there, it should be able to connect elsewhere... thoughts? appreciate your help, brian <{POST_SNAPBACK}>
Jack_mcs Posted December 6, 2004 Posted December 6, 2004 I don't think you need the extra call to connect to the db. Download the lastest version of Header Tags and look at the database_setup.sql file I added. It connects to the database and reads in the information fine. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
bmac Posted December 6, 2004 Author Posted December 6, 2004 I just downloaded the file & see what you mean. I tried ditching the inital call to the DB but all I get is: "No Database Selected" How does your file select the DB? Thanks, appreciate the help. Brian info I don't think you need the extra call to connect to the db. Download the lastest version of Header Tags and look at the database_setup.sql file I added. It connects to the database and reads in the information fine. Jack <{POST_SNAPBACK}>
Jack_mcs Posted December 6, 2004 Posted December 6, 2004 Be sure to nclude this line require('includes/application_top.php'); which connects to the db for you. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
bmac Posted December 6, 2004 Author Posted December 6, 2004 I tried including that line but I keep getting a jumble of errors (and on top of it an error that says Access Denied for user brian_osc). I think I'm confusing even myself, so let me start again: We have a computer system at work that keeps track of our orders, inventory, etc. We're trying to write an extra little program that we can run that will pull information out of our DB and download it to a CSV file onto our computers. I've tried a series of ways to connect to the DB, but they don't work. Any ideas? Thanks so much, Brian Be sure to nclude this linerequire('includes/application_top.php'); which connects to the db for you. Jack <{POST_SNAPBACK}>
Jack_mcs Posted December 6, 2004 Posted December 6, 2004 Edit the file I mentioned so that it only contaiins the following (leave all the html in tact). require('includes/application_top.php'); $htc_check_query = tep_db_query("select * from products_description"); for ($ctr = 0; $ctr < tep_db_fetch_fields($htc_check_query); $ctr++) { if (false != strstr(mysql_field_name($htc_check_query, $ctr), 'products_head_title_tag')) { echo 'Looks like Header Tags is already installed. Aborting...'; tep_exit(); } } echo 'HTC not installed'; This should run and ell you whether or not HTC is installed. If it fails to run, then you have an issue with your server. If this is a working site, I don't see how it could fail since, presumably, the rest of your shop works and these are common calls. For example, does your contact us page work? If not, then you've got to fix those problems first. It the above code works, then edit the file to search the table you need and proceed from there. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
bmac Posted December 8, 2004 Author Posted December 8, 2004 This works! Thank you _very_ much. I'll start working with actually retrieving the data & displaying it now. I really appreciate your help Jack, thanks. Brian Edit the file I mentioned so that it only contaiins the following (leave all the html in tact). require('includes/application_top.php'); $htc_check_query = tep_db_query("select * from products_description"); for ($ctr = 0; $ctr < tep_db_fetch_fields($htc_check_query); $ctr++) { if (false != strstr(mysql_field_name($htc_check_query, $ctr), 'products_head_title_tag')) { echo 'Looks like Header Tags is already installed. Aborting...'; tep_exit(); } } echo 'HTC not installed'; This should run and ell you whether or not HTC is installed. If it fails to run, then you have an issue with your server. If this is a working site, I don't see how it could fail since, presumably, the rest of your shop works and these are common calls. For example, does your contact us page work? If not, then you've got to fix those problems first. It the above code works, then edit the file to search the table you need and proceed from there. Jack <{POST_SNAPBACK}>
Recommended Posts
Archived
This topic is now archived and is closed to further replies.