Jump to content
Larry Ullman's Book Forums

Leaderboard

Popular Content

Showing content with the highest reputation since 03/17/11 in all areas

  1. The other day, I wanted to use the mysqli_connect function to connect to a DB on an external host that was not 'localhost'. Specifically, I was using XAMPP on a computer and was trying to connect to to a DB on a separate domain that I own, which is on a server maintained by my hosting company. I have (and know) all the necessary credentials for the DB, but I kept getting errors when trying to connect. I used the same user name, password and DB name as when its 'localhost', by for the host argument, I tried several combinations like domain-name.com, etc., but nothing worked. Does anyone have any experience with this sort of thing and know how to connect to DBs on other hosts? Thanks.
    3 points
  2. It's not all the privileges you need to grant but rather the ability to connect from other hosts, not localhost. Ideally, the connection script is on a fixed IP address and you can grant permissions to dbUser@'ACTUAL IP ADDRESS'. You have to make sure you do that first. The external connections/ports/etc. is a secondary, less common issue.
    3 points
  3. I hear you! Larry's the guru! He's the mastermind genius! You are a brainiac, too, HartleySan! Thanks again for the wonderful assistance! You are by no means a random dude, HartleySan; moreover, you are incredibly kind and extremely helpful--brilliant even--with a wonderful future in Web development! Thanks again!
    2 points
  4. Larry, maybe, but definitely not me. In fact, Larry corrects me all the time. I'm just a random dude hoping to work as a Web developer someday. Anyway, good luck.
    2 points
  5. I think you might be misunderstanding things a bit. To start with, it doesn't really matter where the actual DB files are stored on your localhost because you would never need to manipulate them directly. (If you really are curious though, they're in the xampp\mysql\data\ folder in Windows.) Instead, you should always use some sort of interface application, like phpMyAdmin, to manage and edit your DBs. By using phpMyAdmin, you can also easily import and export databases. In terms of the Web root folder, the one thing that you should probably place outside of it is the PHP file that calls the mysqli_connect function to connect to the DBs. Larry talks a lot about this in his book, so if you follow his advice, you should be fine. I've migrated from my localhost to a Web hosting server many times, and in terms of the DB, things are pretty simple. All you have to do is export the DB from your localhost and then import it from the interface your Web hosting company provides. More specifically, from phpMyAdmin on your localhost, there is an Export tab you can use. Simply select the DB or tables you want to export, and then click the Export button. By default, the exported file will be a .sql file, which should be fine. To import the database, you first need to access the version of phpMyAdmin your hosting service provides for you. The tricky thing is that a lot of hosting services block the Import tab in phpMyAdmin, but luckily, there's an easy workaround. .sql files can be opened in text editors. If you open a .sql file in a text file (which might take a second if the DB is big), you'll see that all it is is a bunch of INSERT statements (and a few other statements) for recreating the DB from scratch. As such, all you have to do is copy all the text in the .sql file, click on the SQL tab in phpMyAdmin, paste all of the SQL code in the text area, hit OK, wait a second, and BOOM! you have your entire DB on your hosting service. That's about it. Let us know if you have any other questions.
    2 points
  6. Hello, friends. Sorry to finish this post with some very basic questions, but I am going to be developing on localhost and then transferring over to a server maintained by a hosting company and had some elementary questions. First,please kindly note that I am wondering where I would place my MySQL databases on localhost to ensure that they are connected with the Web root folder. I'm not sure if I would save them in a specific folder or how to do so, if at all possible. As a matter of fact, I'm not even sure what folder the databases get saved to on my localhost in the first place. Second, I'm wanting to separate my databases as I intend on having multiple Web sites (I have one already and plan on building several more). In what directory could I create a subfolder? How would I transfer this subfolder along with the Web root to the hosting company's server? I know these are probably the most basic questions imaginable to present, and I apologize sincerely for this. Thank you for any and all feedback, my friends, and I wish you all a great day!
    2 points
  7. You're welcome! Thanks for all the help you've provided to others over the years!
    2 points
  8. Okay. Good luck and let us know if you need any other help. As a suggestion, what many people do in this situation is create a service on your hosted site that will provide the necessary database access without directly connecting to MySQL remotely.
    2 points
  9. Originally, the user was using to connect to the DB had only the SELECT and UPDATE privileges, but I temporarily changed it so that the user had all privileges. Even then though, I had no luck in establishing a connection. Also, I appreciate your techie experts advice, but I don't know exactly what they mean by, "make sure that the MySQL server can accept external connections and that it is bound to the correct network interface." Could you possibly provide some more details about how to translate that into actions? Thanks. Also, it should be reiterated that I'm using a MySQL server provided by my hosting company, so I have very limited control over various admin operations.
    2 points
  10. I get the following error: Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'xxx'@'xxx' (using password: YES) in C:\xampp\htdocs\xxx on line 3 Obviously, I have omitted the sensitive data with xxx, but you get the point. Also, I tried granting all privileges to the user, but I still get the same error.
    2 points
  11. What error are you getting? Have you tried GRANT ALL PRIVILEGES ON dbName.* TO dbUser @'%' IDENTIFIED BY 'dbPassword';
    2 points
  12. Thanks for the nice words. Yeesh on this error message, though! That command creates four keys (or indexes): on user_id, on username, on email, and on the combination of username and pass. None of those seems to be 100 bytes! My hunch is it's the login key that's causing the problem. Try removing that from the command (and delete the comma after `UNIQUE (email)` and try it again.
    1 point
  13. I'm not sure I'm following exactly but just to confirm, is your server properly set up to send emails?
    1 point
  14. Hi All, Here is my solution to Pursue exercises in CH3. I combined 4 questions into one script. If you could take a look at my code and correct if I am wrong, I would be reaaaaly appreciated! Here are the questions on the book: # 1. Change calculator.php so that it uses a constant in lieu of the hard-coded average speed of 65. # 2. Better yet, modify calculator.php so that the user can enter the average speed or select it from a list # of options. # 3. Update the output of calculator.php so that it displays the number of days and hours the trip will take, when the number of hours is greater than 24. # 4. As a more advanced trick, rewrite calculator.php so that the create_radio( ) function call is only in # the script once, but still creates three radio buttons. Hint: Use a loop. Here is my solution script: ( I highlighted the code for the solution ) <?php # Script 3.10 - calculator.php #5 - Pursue # 1. Change calculator.php so that it uses a constant in lieu of the hard-coded average speed of 65. # 2. Better yet, modify calculator.php so that the user can enter the average speed or select it from a list # of options. # 3. Update the output of calculator.php so that it displays the number of days and hours the trip will take, # when the number of hours is greater than 24. # 4. As a more advanced trick, rewrite calculator.php so that the create_radio( ) function call is only in # the script once, but still creates three radio buttons. Hint: Use a loop. # # // This function creates a radio button. // The function takes two arguments: the value and the name. // The function also makes the button "sticky". function create_radio($value, $name = 'gallon_price') { // Start the element: echo '<input type="radio" name="' . $name . '" value="' . $value . '"'; // Check for stickiness: if (isset($_POST[$name]) && ($_POST[$name] == $value)) { echo ' checked="checked"'; } // Complete the element: echo " /> $value "; } // End of create_radio() function. // This function calculates the cost of the trip. // The function takes three arguments: the distance, the fuel efficiency, and the price per gallon. // The function returns the total cost. function calculate_trip_cost($miles, $mpg, $ppg) { // Get the number of gallons: $gallons = $miles / $mpg; // Get the cost of those gallons: $dollars = $gallons * $ppg; // Return the formatted cost: return number_format($dollars, 2); } // End of calculate_trip_cost() function. $page_title = 'Trip Cost Calculator'; include ('includes/header.html'); // PURSUE 1 - Define the constant for average speed: define ('AVERAGE_SPEED', 65); // Check for form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Minimal form validation: if (isset($_POST['distance'], $_POST['gallon_price'], $_POST['efficiency'], $_POST['average_speed']) && is_numeric($_POST['distance']) && is_numeric($_POST['gallon_price']) && is_numeric($_POST['efficiency']) && is_numeric($_POST['average_speed'])) { // Calculate the results: $cost = calculate_trip_cost($_POST['distance'], $_POST['efficiency'], $_POST['gallon_price']); //$hours = $_POST['distance'] / AVERAGE_SPEED; $hours = $_POST['distance'] / $_POST['average_speed']; // PURSUE 3 - Calculate days and modulus $days = $hours / 24; $days_modulus = $days % 24; // PURSUE 3 - Print the results, using Days and Hours if ( $hours <= 24) { echo '<h1>Total Estimated Cost</h1> <p>The total cost of driving ' . $_POST['distance'] . ' miles, averaging ' . $_POST['efficiency'] . ' miles per gallon, and paying an average of $' . $_POST['gallon_price'] . ' per gallon, is $' . $cost . '. If you drive at an average of ' . $_POST['average_speed'] . ' miles per hour, the trip will take approximately ' . number_format($hours, 2) . ' hours.</p>'; } else { echo '<h1>Total Estimated Cost</h1> <p>The total cost of driving ' . $_POST['distance'] . ' miles, averaging ' . $_POST['efficiency'] . ' miles per gallon, and paying an average of $' . $_POST['gallon_price'] . ' per gallon, is $' . $cost . '. If you drive at an average of ' . $_POST['average_speed'] . ' miles per hour, the trip will take approximately ' . number_format($days, 2) . ' days and ' . $days_modulus . ' hours.</p>'; } } else { // Invalid submitted values. echo '<h1>Error!</h1> <p class="error">Please enter a valid distance, price per gallon, fuel efficiency and average speed.</p>'; } } // End of main submission IF. // Leave the PHP section and create the HTML form: ?> <h1>Trip Cost Calculator</h1> <form action="" method="post"> <p>Distance (in miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?>" /></p> <p>Ave. Price Per Gallon: <span class="input"> <?php // PURSUE 4 the create_radio( ) function call is only in the script once // Step 1: create an array to hole the three radio button values: $radio_values = array('3.00', '3.50', '4.00', '5.00'); // Step 2: use a foreach loop to loop through the array: foreach ($radio_values as $radio_value) { create_radio($radio_value); } //create_radio('3.00'); //create_radio('3.50'); //create_radio('4.00'); ?> </span></p> <p>Fuel Efficiency: <select name="efficiency"> <option value="10"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '10')) echo ' selected="selected"'; ?>>Terrible</option> <option value="20"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '20')) echo ' selected="selected"'; ?>>Decent</option> <option value="30"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '30')) echo ' selected="selected"'; ?>>Very Good</option> <option value="50"<?php if (isset($_POST['efficiency']) && ($_POST['efficiency'] == '50')) echo ' selected="selected"'; ?>>Outstanding</option> </select></p> <!-- // PURSUE 2 - Let user enter average speed: (Select from a list of options is not implemented here) --> <p>Average Speed: <input type="text" name="average_speed" value="<?php if (isset($_POST['average_speed'])) echo $_POST['average_speed']; ?>"></p> <p><input type="submit" name="submit" value="Calculate!" /></p> </form> <?php include ('includes/footer.html'); ?>
    1 point
  15. Hey guys! Maybe it is not the right place to post, if so, dear admins, please, move it to the right place. tWe look for a few beta users for our new ZoomAdmin platform (www.zoomadmin.com), which will be lunched in QA1 of 2019. We are still in the development but there are screenshots and youtube demo videos available. If anyone is interested, please, ping me. Thanks. Angela A. ZoomAdmin team.
    1 point
  16. Hey Julien! So long as you're never storing anything sensitive in your local MySQL database, I don't think it's a problem to leave the password unchanged. And, if you change the root password in MySQL, you'll need to change your phpMyAdmin config, too. So that's another argument against. That being said, what you're doing wrong is not using the correct current password! According to Google searches (and I thought I said this in the book), the default root user password should be "root".
    1 point
×
×
  • Create New...