Chapter 4
Chapter 4
host: It is optional and it specify the host name or IP address. In case of local
server localhost is used as a general keyword to connect local server and run the
program.
username: It is optional and it specify mysql username. In local server username
is root.
Password: It is optional and it specify mysql password.
database_name: It is database name where operation perform on data. It also
optional.
Return values:
It returns an object which represent MySql connection. If connection failed then
it return FALSE.
Program: Below is the implementation of mysqli_connect() function.
<?php
mysqli_connect("localhost", "root", "", "GFG");
if(mysqli_connect_error())
echo "Connection Error.";
else
echo "Database Connection Successfully.";
?>
Output:
<?php
$host = 'localhost:3306';
$user = '';
$pass = '';
$dbname = 'test';
$id=2;
$name="Rahul";
$salary=80000;
$sql = "update emp4 set name=\"$name\", salary=$salary where id=$id";
if(mysqli_query($conn, $sql)){
echo "Record updated successfully";
}else{
echo "Could not update record: ". mysqli_error($conn);
Output:
} Connected successfully
mysqli_close($conn); Record updated successfully
?>
PHP MySQL Select Query