Connecting PHP MySQL
Connecting PHP MySQL
l
when sending data to and from the database server:
4 Next, complete this script by adding instructions to
$dbc = mysqli_connect ( ‘host’, ‘user’, ‘password’, ‘database’ ) display connection information if the attempt has
OR die ( mysqli_connect_error() ) ;
succeeded
mysqli_set_charset( $dbc, ‘charset’ ) ; # Display MySQL version and host.
if( mysqli_ping( $dbc ) )
You need not understand in detail how the script works at this { echo ‘MySQL Server ‘ . mysqli_get_server_info( $dbc ).
stage, but recognize that it contains sensitive information. For ’connected on ‘ . mysqli_get_host_info( $dbc ) ; }
this reason it should not be placed in the web server’s /htdocs
directory like all other PHP scripts, where its contents may be
accessible, but placed instead safely in /htdocs parent directory
– for example, in the “C:/Abyss Web Server” directory rather
l 5 Save the script in your web server’s /htdocs directory as
require.php, then open it in your browser (via HTTP) to
see the connection details on successful connection
than in the “C:/Abyss Web Server/htdocs” directory.
Any PHP script can incorporate another PHP script by
using a “require” statement to specify the other script’s path.
This feature can be used to good effect to incorporate the
connection script without revealing its sensitive information.