Chapter 9 Using PHP with MySQL
header.html Script 9.1 on page des/header.html des/header.html ch09\includes\header.html
mysqli_connect.php Script 9.2 on page qli_connect.php qli_connect.php ch09\mysqli_connect.php
Invalid Password qli_connect2.php qli_connect2.php Could not connect to MySQL: Access denied for user (using password: YES)
Access Information // Set the database access information as constants: DEFINE ('DB_USER', 'frank'); DEFINE ('DB_PASSWORD', '); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'db_frank');
mysqli_connect $dbc (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: '. mysqli_connect_error() );
Protecting Connection Information Page 270 Figure B Store connection information outside of (htdocs folder) Use.php extension
sql.sql Use only Chapter 5 USE db_frank;
users table mysql -h cscdb.nku.edu -u frank -p <sql.sql mysql -h cscdb.nku.edu -u frank –p mysql> use db_frank; Database changed mysql> show tables; mysql> select * from users;
register.php Script 9.3 on page ter.php ter.php ch09\script_09_03\register.php
Running MySQL Query // Make the query: $q = "INSERT INTO users (first_name, last_name, , pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )"; // Run the query. $r ($dbc, $q); if ($r) { // If it ran OK.