2

so I'm making a super simple site just for practice where you type something in an then its displayed on the page, but it wont work and i think iv narrowed it down to the begining where it connects to the database just

$server    ="localhost";
$username  ="root";
$password  ="********";
$database  ="user_accounts"; 
$connect=mysqli_connect($server,$username,$password,$database);

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

Im running my server using Apache/2.2.22 (Debian), PHP 5.4.4-14 and mysql Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (armv7l) using readline 6.2 and I've noticed that even when I type the password incorrectly it doesn't 'echo' the error line, so my question is do I connect to localhost like that or did i do something else wrong in there?

user1895629
  • 147
  • 1
  • 1
  • 8
  • also i hate using the root login, if anyone could give me the sql code to make a read and write user only thatd help out a lot – user1895629 May 22 '13 at 04:13

3 Answers3

1

Try something like this:

if ($mysqli->connect_errno) {
    printf("Failed to connect: %s\n", $mysqli->connect_error);
    exit();
}
mogul
  • 4,441
  • 1
  • 18
  • 22
1

Could you Try this

<?php
$mysqli = @new mysqli('localhost', 'root', '*******', 'user_accounts');

if ($mysqli->connect_errno) {
    die('Connection Error: ' . $mysqli->connect_errno);
}
?>
Ahmed Z.
  • 2,329
  • 23
  • 52
1

Connect like below

<?php
$link = @mysqli_connect('localhost', 'root', '*******', 'user_accounts');

if (!$link) {
    die('Connect Error: ' . mysqli_connect_errno());
}
?>

Below is create user in mysql script on your request

User newuser to connect with no password (which is insecure), include no IDENTIFIED BY clause:

CREATE USER 'newuser'@'localhost';

To assign a password to new created user newuser, use IDENTIFIED BY with the plaintext password value:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'mypass';

To avoid specifying the plaintext password if you know its hash value (the value that PASSWORD() would return for the password), specify the hash value preceded by the keyword PASSWORD:

CREATE USER 'newuser'@'localhost'
IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689';

Then you can GRANT access of what ever you want to that newuser

GRANT SELECT,INSERT,UPDATE,DELETE ON user_accounts.* TO 'newuser'@'localhost';

You can use this link to generate the hash code.

Yogus
  • 2,307
  • 5
  • 20
  • 38