I have a main page on my site and I am trying to make a connection to the MySQL server and get some data from the database. But the problem is that when I want to establish a connection I have to put the username and password in the page which doesn't seem wise to me. I added a part of my code related to this problem. &lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $host = &quot;localhost&quot;; $userName = &quot;username&quot;; $password = &quot;12345678&quot;; $dbName = &quot;MyDB&quot;;  $connection = new mysqli($host , $userName , $password , $dbName); if ($connection-&gt;connect_error) {     die(&quot;Connection failed due to this error : &quot; . $connection-&gt;connect_error . '&lt;br&gt;'); } else{     echo &quot;Connected successfully&quot;; { &lt;/body&gt; &lt;/html&gt;
27997
When a PHP application makes a database connection it of course generally needs to pass a login and password. If I'm using a single, minimum-permission login for my application, then the PHP needs to know that login and password somewhere. What is the best way to secure that password? It seems like just writing it in the PHP code isn't a good idea.
14163
I'm trying to install MySQL on Ubuntu Natty without the password prompt. However, I keep getting prompted for a password at some stage after the main installation.  Also, when I do enter what I believe should be my password (mymysqlpass), it gives me an access denied notice. Then when the script terminates, I can login to mysql without a password i.e. mysql -uroot, which should not happen.  #!/bin/bash #This script installs mysql (latest build) #Install MYSQL Server mysql_pass=mymysqlpass export DEBIAN_FRONTEND=noninteractive  debconf-set-selections &lt;&lt;&lt; 'mysql-server-5.1 mysql-server/root_password password '$mysql_pass'' debconf-set-selections &lt;&lt;&lt; 'mysql-server-5.1 mysql-server/root_password_again password '$mysql_pass'' apt-get -y install mysql-server #Configure Password and Settings for Remote Access cp /etc/mysql/my.cnf /etc/mysql/my.bak.cnf ip=`ifconfig eth0 | grep "inet addr"| cut -d ":" -f2 | cut -d " " -f1` ; sed -i "s/\(bind-address[\t ]*\)=.*/\1= $ip/" /etc/mysql/my.cnf mysql -uroot -e "UPDATE mysql.user SET Password=PASSWORD('"$mysql_pass"') WHERE User='root'; FLUSH PRIVILEGES;" sleep 10 mysql -uroot -p$mysql_pass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '"$mysql_pass"'; FLUSH PRIVILEGES;" #Restart service mysql restart echo "MySQL Installation and Configuration is Complete."
110884
I have a MySQL Community database on a remote server and I am trying to get Microsoft Access to read data from it. This data is sensitive. The problem is, MySQL doesn't care about the username that I give it in the .DSN file. It lets me read the ENTIRE database no matter what! How do I get it to actually check the username that I give it in the .DSN file?  edit: I'm not a DBA, I'm some intern who is over his head. Please don't assume that I know anything about anything  :)
47807
I have been given a Drupal site which I have to get it running.  I have Apache / Drupal / MySQL up and running, and created a new .conf file in Active Sites, and set the document location to /var/www/html/  I have edited my hosts file so that I have an entry for   127.0.0.1 samplesite.com   If I browse to samplesite.com/index.php I see the index of the site. So far so good. It is all styled, and as I see genuine content I must be hitting the database  Now no matter what link I click on on that page, I get a 404 error. (Looking in the log files its a 404 523 error if that has any bearing on it.)  I then found out the admin userid (using drush), reset the password, and cleared all caches. Still the 404 errors.  If I go to samplesite.com/user or samplesite.com/admin, I still get the 404 error, not an admin login page.  As this is an existing site, and works online, I am blaming something in my setup / configuration (being as the url on a failed link is similar to samplesite.com/about, I am assuming it is in the navigation configuration, but now I am stuck).  Is there an apache url rewriting module (or drupal one?) that needs some configuration? Or can anyone suggest something else I may have overlooked in apache / drupal configuration?  I now have the line $base-url = 'samplesite.com'; in my settings.php file, and none of the other urls work. However it accepts that I am logged in as admin as I have an additional admin menu at the top of the page. (none of the links work though) Curiously, if I disable wifi, then the page doesn't load at all (I wouldn't have thought that wifi on or off would affect localhost)  Ok, My fix came when I followed this thread   I needed to add in the following.  &lt;Directory /var/www/html&gt;    RewriteEngine on    RewriteBase /    RewriteCond %{REQUEST_FILENAME} !-f    RewriteCond %{REQUEST_FILENAME} !-d    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] &lt;/Directory&gt;   However I only got here because of the help I received along the way, I think this was just the missing piece.
106111
I have already uploaded some files in the free web host I chose and created a database there using phpMyAdmin v2.11.4  Also, I have Googled first this question before posting this here but I don't understand some rules and I need a clarification.  The exact error I get from viewing my uploaded file(index.php) is this:  Warning: mysqli_connect() [function.mysqli-connect]: (HY000/1130): Host '31.170.160.98' is not allowed to connect to this MySQL server in /home/a6400350/public_html/subdomains/index.php on line 7   Domain name of free web host I'm using is   And my php code for connecting to host is:  &lt;?php  $host = "sql10.000webhost.com"; //or "31.170.160.98" $username = "a6400350xxxxxx"; $password = "••••••••";  $con = mysqli_connect($host, $username, $password);  ?&gt;    I also check if the server is down  or it's just me There was also no previlege section in phpMyAdmin page as other suggest   Don't I have any permission to connect programmatically to this host as I am just a free user?  Edit     I'm also thinking of uploading the whole XAMPP in the server so I   could do the things I'm imagining.   Edit 2     Also one more thing, I imported the database by means of .sql file   locally through that server, maybe this has something to do about it?
118672
I am totally new in linux/ubuntu I am trying to setup lamp on my OS, however I've installed apache , php , mysql by following commands:  sudo apt-get install apache2 sudo apt-get install php5 sudo apt-get install libapache2-mod-php5 sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql sudo apt-get install phpmyadmin   everything works fine except that i totally cannot log into MySQL(which leads to phpmyadmin failure login) getting the errors :   #1045 Cannot log in to the MySQL server Access denied for user 'root'@'localhost' (using password: YES)   I googled the problem and also I have tried to reinstall  all installed components, but the same result came up!   in windows i usually modified the content of mysql configure file but in ubuntu nothing is as same as windows!:)  can anybody help me on this, really need to setup lampp :-S  thanks in advanced
6735
I've got a working PHP script that gets Longitude and Latitude values and then inputs them into a MySQL query. I'd like to make it solely MySQL. Here's my current PHP Code:  if ($distance != "Any" &amp;&amp; $customer_zip != "") { //get the great circle distance      //get the origin zip code info     $zip_sql = "SELECT * FROM zip_code WHERE zip_code = '$customer_zip'";     $result = mysql_query($zip_sql);     $row = mysql_fetch_array($result);     $origin_lat = $row['lat'];     $origin_lon = $row['lon'];      //get the range     $lat_range = $distance/69.172;     $lon_range = abs($distance/(cos($details[0]) * 69.172));     $min_lat = number_format($origin_lat - $lat_range, "4", ".", "");     $max_lat = number_format($origin_lat + $lat_range, "4", ".", "");     $min_lon = number_format($origin_lon - $lon_range, "4", ".", "");     $max_lon = number_format($origin_lon + $lon_range, "4", ".", "");     $sql .= "lat BETWEEN '$min_lat' AND '$max_lat' AND lon BETWEEN '$min_lon' AND '$max_lon' AND ";     }   Does anyone know how to make this entirely MySQL? I've browsed the Internet a bit but most of the literature on it is pretty confusing.
58273
I know that php has md5(), sha1(), and the hash() functions, but I want to create a hash using the MySQL PASSWORD() function.  So far, the only way I can think of is to just query the server, but I want a function (preferably in php or Perl) that will do the same thing without querying MySQL at all.  For example:  MySQL hash -> 464bb2cb3cf18b66  MySQL5 hash -> *01D01F5CA7CA8BA771E03F4AC55EC73C11EFA229  Thanks!
30010
Help!  I have a PHP (PHP 5.2.5) script on HOST1 trying to connect to an MySql database HOST2. Both hosts are in Shared Host environments controlled through CPanel.  HOST2 is set to allow remote database connections from HOST1.  The PHP connect I'm using is:-     $h2 = IPADDRESS;     $dbu = DBUSER;     $dbp = DBPASS;  $DBlink = mysql_connect($h2, $dbu, $dbp);   This always fails with:-  Access denied for user '&lt;dbusername&gt;'@'***SOMESTRING***' (using password: YES)   nb: SOMESTRING looks like it could be something to do with the shared host environment.  Any ideas???  BTW: I can make remote connections to HOST2 from my laptop using OpenOffice via ODBC, and SQLyog. The SQLyog and ODBC settings are exactly the same as the PHP script is trying to use.
40022
How do I connect to a MySQL database using a python program?
71838
I created file node--my_content_type.tpl.php, where I'd like to print the username as string. I tried the following code, but unfortunately it doesn't work. How can I do it?  &lt;?php    print $name; ?&gt;
92994
I have an HTML form - with PHP, I am sending the data of the form into a MySQL database. Some of the answers to the questions on the form have checkboxes. Obviously, the user does not have to tick all checkboxes for one question. I also want to make the other questions (including radio groups) optional.  However, if I submit the form with empty boxes, radio-groups etc, I received a long list of 'Undefined index' error messages for each of them.  How can I get around this? Thanks.
1754
Basically, one of the greatest questions of all time: What are some ways you're using settings.php in your development/staging workflow?  Right now, I have my settings.php file set up like the following, and I base my development on the server's $HOST directive—meaning I can work on dev.example.com for the development (shared) server, local.example.com for my local computer (and other dev's local code checkouts), and www.example.com (or just example.com) for the live site.  (This code is in the 'Database settings' section of settings.php):       $host = $_SERVER['HTTP_HOST']; $base_url = 'http://'.$host; $cookie_domain = $host;  switch($host) {   case 'example.com': # Production server     $db_url = 'mysqli://prod_sql_user:password@127.0.0.1/prod_db';     $update_free_access = FALSE;     $conf = array (       // Set production config options here...       'example_setting' =&gt; 0,     );     break;    case 'dev.example.com': # Development server     $db_url = 'mysqli://dev_sql_user:password@127.0.0.1/dev_db';     $update_free_access = FALSE;     $conf = array (       // Set production config options here...       'example_setting' =&gt; 0,     );     break;    case 'local.example.com': # Local server     $db_url = 'mysqli://local_sql_user:password@127.0.0.1/local_db';     $update_free_access = FALSE;     $conf = array (       // Set production config options here...       'example_setting' =&gt; 0,       // Turn off most core caching.       'cache_inc' =&gt; 'includes/cache.inc',       'cache' =&gt; CACHE_DISABLED,     );     break;  } ?&gt;   This works pretty well for most purposes, but it means we have a lot of extraneous code sitting around in our shared settings.php file... is there a better way?
77056
I have configured my MySQL Database to require passwords on all users, even root from the machine itself.  Now I discovered that there are empty Users in my Database  Reproduce: mysql -u root -p and then use mysql; &amp; select * from user;  It gives me 2 entries, one with "localhost" and user &lt;empty&gt; and one with the machine's hostname and &lt;empty&gt;.  Now I tried to access the account with mysql -u ' ' (yes it's correct, leave a space between the ' things) and I log in without a password. The user can "only" see information_schema and test, the two databases created by default. He does not has access to mysql or any other custom created databases.  I already changed the Password of this user to something I won't tell you  mysql -u root -p use mysql; UPDATE mysql.user SET Password=PASSWORD('thisisasecretpassword') WHERE USER='root'; FLUSH PRIVILEGES;   Now my Questions:   Is any MySQL Server vulnerable for an attack with this entry? Could an attacker break out of this account or the two default databases? Should I password-protect those Users or can I delete them? Are They required for some MySQL-internal things?
84550
I have MySQL password saved on a file foo.php, for example P455w0rd, when I try to use it:  $ cat foo.php | grep '$dbpwd=' | cut -d '"' -f 2 | mysql -U root -p mydb -h friendserver Enter password: (holds)  $ echo P455w0rd | mysql -u root -p mydb -h friendserver Enter password: (holds)   Both option still ask for password, what's the correct way to send password from stdin?
118052
Our MySQL log displayed a warning on restart about 2 root users not having passwords.  I went into MySQL and checked all users:  mysql&gt; select * from mysql.user;   and see:  Host       |    User   |   Password localhost       root      *76685yt868itetc web12-b0        root 127.0.0.1       root     First off, why are there 3 root users (and do we need 127.0.0.1 since we have localhost)?  Second, why would two of them not have passwords set?  Third, do the web12-b0 and 127.0.0.1 hosts have full root access without having to use a password (as it appears)?  Fourth, is there some valid reason for this or should I suggest the admin put passwords on those two hosts?  Thanks for your answers.
83543
, which is linked from site-specific blogs, says  Error establishing a database connection  I believe this is an error.