|
how to connect to database
|
|
|
above image displays list of servers available in the php my
admin
|
|
|
<?php
|
|
|
mysqli_connect('localhost', 'root', '');
|
to conect to the server using mysqli_connect , use arguments ist one is host , and
username and password
|
|
?>
|
if it is connceted, nothing it displays, if we write excho, it
shows it conncected
|
|
store into variables and connect
|
|
|
<?php
|
|
|
$host = 'localhost';
|
if it is conncected to server , otherewise if it cant connect,
it shows , could not open
|
|
$user = 'root';
|
|
|
$pass = '';
|
|
|
@mysqli_connect($host, $user, $pass) or die('could not open');
|
|
|
?>
|
|
|
<?php
|
|
|
$host = 'localhost';
|
|
|
$user = 'root';
|
|
|
$pass = '';
|
|
|
@mysqli_connect($host, $user, $pass) or die('could not open');
|
if it is connected to the server, it will go to next otherewise
it wil not eexecute next statements
|
|
echo 'connected to the server';
|
if it is conncected, it displays,, connected to the serverd
|
|
|
we connected to the server, we have to conncect to the data base
|
|
@mysqli_select_db(@mysqli_connect($host, $user, $pass),
'mydatabase') or die('could not connect');
|
from server, it connects to the data base, if not conccet, it
wil die and display could not coonce
|
|
echo 'connected to the db';
|
if it successfully connect to the data base,, it wil show the connected to database
|
|
?>
|
|
Tuesday, 9 June 2020
how to connect to database
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment