Mysqli using in php - Mostlikers

31 July, 2013

Mysqli using in php

Mysqli is a database system used on the web its runs on a server side. Mysql query used to transaction the client data to store the server table. This is sort database storage it’s not possible millions of people access database so PHP team announced plans to deprecate MySQL extension alternatives on introduce Mysqli - "i" is standing improvement its based object oriented implementation.  MySQLi supports prepared statements, transactions and multiple statements. 

How to connect database using Mysqli

In Previously using Mysql query connect  on database watch below coding difference on mysql and mysqli

Mysql Database connection
$conn=new mysqli('localhost','user','password','login');
    echo "good";

Mysqli Database connection
$conn = new mysqli('localhost', 'user', 'password', 'tablename');
if($conn->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');

Mysqli Query extension similar to Mysql Query extension watch below Insert,View,Update,Delete coding its connections using on object oriented way.

Mysqli insert statement
Insert Post value in database this coding same to Mysql syntax using oops concept directly link on database file $conn->query("statement") in Mysql syntax as Mysql_query("statement") so just simple change the coding on oops based.

$insert=$conn->query("insert into tablename(field name) values('$post value')");

Mysqli fetch statement
Fetch syntax also same but object based fetch the statement little bit changed if you like fetch on Array method change  mysqli_fetch_array($sql) 

$sql=$conn->query("SELECT * FROM `tablename`");
    echo $page->table_feld;
Delete and update coding on same syntax way connect to change the query method

Escaping Characters
Without using escape string post  value  in  database $menu=$_POST['menu'];  its  not secure if any users enter single quotes or backslash on post value produce error, so avoid this type way using mysqli_real_escape_string($_POST['menu']); this is a correct statement method.

Advantages of Mysqli
  • Mysqli is  support to the Embedded server 
  • concept based on oops interface 
  • Mysqli support multiple statement 
  • It's Enhanced debugging capabilities  
Don't using mysql functions its fully deprecate extension. try mysqli function or PDO function its object based statement simplify the coding statement.  


  1. Good overview, for security its better to use prepared statements then escaping them.

  2. Replies
    1. thanks to comment this post joseph benz

  3. Try to explain OOPS format....

  4. Try to install this widget in your blogger you get more response and share and comment easily dear brother.....

  5. Failed to connect to MySQL: User user_name already has more than 'max_user_connections' active connections

    how to solve this problem