Pages

Wednesday, August 20, 2014

PHP - Connecting to MYSQL and running queries

TIDBIT blogtorial - Short and informational.

MYSQL connection and handling queries
 // Create connection  
 $con=mysqli_connect("localhost","username","password","dba");  
 // Check connection  
 if (mysqli_connect_errno()) {  
      echo "Failed to connect to MySQL: " . mysqli_connect_error();  
 }  

 //Query String  
 $current_query = "select test from testtable";  
 //Get the results  
  $current_query_result = mysqli_query($con,$current_query);  
 //Loop through the results  
    while ($row = mysqli_fetch_array($current_query_result, MYSQL_NUM)) {  
     echo "Row value is $row[0]\n";  
    }

Many more articles to come so ....

Please subscribe/comment/+1 if you like my posts as it keeps me motivated to write more and spread the knowledge.