Skip to main content

Simple mysqli connection and some tips

Simple mysqli connection:



<?php
$conn1=mysqli_connect("localhost","root","","databasename");
if($conn1)
{
    echo "<script>console.log('Connection ok');</script>";
}else{
    echo "<script>console.log('Connection not ok');</script>";
}
?>  



Mysqli is the improved version of mysql. Now-a-days whenever you write mysql, it will show you error as mysqli is introduced. To use mysqli such as mysqli_query all you need to do is just put your connection name Ex: $conn1 (like our code) in your mysqli_query. Ex:

mysqli_query($conn1, "SELECT * FROM databasename"); 

Some mysqli functions which is used frequently are given below:
mysqli_query() 
mysqli_num_rows()
mysqli_fetch_assoc()
mysqli_fetch_array()
mysqli_close()
mysqli_connect_error()
mysqli_error()
mysqli_fetch_all()
mysqli_free_result()

Comments