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

Popular posts from this blog

Laravel Vuejs Basic Setup

In this article we will see how to setup vue with laravel. 1) Create a laravel project: laravel new laravue 2) In web.php create a temporary route:  Route :: get ( '/test' ,  function  () {      return   view ( 'welcome' ); }); So, when you will see the welcome page once you hit the  http://laravue.test/test  url. 2) In terminal run:  npm install 3) npm install vue (In package.json file you will see that vue dependency has been added successfully) 4) Now go to resources -> js -> app.js file. Here we will have to load the vue. write the following lines in app.js.  require ( './bootstrap' ); window . Vue  =  require ( 'vue' ); const   app  =  new   Vue ({      el :   '#app' }); (Here, vue js will execute and control anything that will be inside the app id. So, for our example  let's put the app id inside the welcome view). So, inside welcome.blade.php 's body...