In the WinMySQLAdmin under the my .ini Setup tab it says:
user=Brad
password=passwordmy PHP reads:
$conn = mysql_connect("localhost", "Brad", "password");
echo $conn;I get this error message:
Warning: mysql_connect(): Access denied for user: 'Brad@localhost' (Using password: YES) in .../mysql_test.php on line 9
If anyone knows why I can't log into my own database, I would greatly appreciate any help!! (I'm able to create and edit my databases in mysql.exe)
Thanks!
Hi,
Use the command line mysql program to do these steps.
Create your database:
mysql> CREATE DATABASE test_database;
mysql> USE test_database;
mysql> CREATE TABLE test_table (firstname VARCHAR(20), lastname VARCHAR(20));
mysql> INSERT INTO test_table VALUES ('John', 'Doe');
mysql> GRANT ALL PRIVILEGES ON test_table.* TO [insert_username_here]@localhost IDENTIFIED BY '[insert_password_here]';
mysql> FLUSH PRIVILEGES;Ok, now you'll need the PHP code to read from the database...
<?
// Define variables
$host="localhost"; // location of MySQL server
$user="john"; // username you set in the GRANT ALL PRIVILEGES... query
$pass="secret"; // password you set in the GRANT ALL PRIVILEGES... query
$db="test_database"; // database to connect to
$query="select * from test_table;"; // query to run on database// Connect to the database
$link = mysql_connect($host, $user, $pass) or die("Could not connect to database: " . mysql_error());// Select the correct database
mysql_select_db($db) or die("Could not select database: " . mysql_error());// Run a query on the database
$result=mysql_query($query) or die("Could not run query: " . mysql_error());// Show results
$rows=mysql_num_rows($result);
$fields=mysql_num_fields($result);print("<table>"); // Start the whole new table in the HTML page
// Show the result
for($i=0; $i<$rows; $i++) { // number of rowsprint("<tr>"); // Start a new row in the HTML page
$row=mysql_fetch_row($result); // Get a row of datafor($k=0; $k<$fields; $k++) { // number of fields
print("<td>"); // Start a new cell in the HTML page
print("$row[$k]"); // Print the field data
print("</td>"); // End the cell in the HTML page
}print("</tr>"); // End the row in the HTML page
}print("</table>"); // End the whole table in the HTML page
// Free result in memory
mysql_free_result($result);// Close the connection
mysql_close($link);?>
Hope this helps!!
| « C++: How to inherit a tem... | Keyboard Capturing » |
Get Solutions to your Hi-Tech Issues Now!