How to connect to mysql in MapReduce temporarily?

How do you connect to MySQL?

  • Over the past few days I have been trying to learn how to use MySQL in correlation with PHP. Every time I try to connect to MySQL using this code: <?php mysql_connect(); ?> I am given an error saying "Access Denied...". I noticed however that the connection function has a user and a password parameter. Do you need a password/username to connect to MySQL? My website is being hosted for free on www.freewebhostingarea.com. I think that they said that they had MySQL support, but they never mentioned a username or a password. Could someone please help me? I am utterly clueless. Thank you!

  • Answer:

    First of all, you should use MySQLi instead of MySQL with PHP (don't worry, it's almost the same). http://php.net/mysqli Secondly, you'll probably have to go into the control panel of your website and create a database and a user, or at least get some more in-depth instructions there (as it may vary from hosting company to hosting company). Thirdly, you will have to connect to the server like this: <?php $connection = mysqli_connect('sql.someserver.com', 'username', 'password'); ?> And if you already know how to use MySQL, just replace mysql_ in the functions with mysqli_, and it'll work just fine.

Mark at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

If your website is hosted for you, you most likely need to set up the database. There should be a link somewhere to your databases. Click that button and request for a database to be set up. The user/pwd should be given when the database is set up. You can then connect to it using that information.

Mike P

<?php $username = "your_userName";//db username $password = "your_password";//db password $hostname = "localhost"; $db = "you_DbName"; //put the database name here //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db($db,$dbhandle) or die("Could not select examples"); ?> you would use code like this.

Vincent Micchia

A database always requires a username and password, otherwise everyone could read and write to it, which is not desired. Contact your hosting provider for the information which you require.

Arie

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.