Example of mysqli connection with the object method:
<?php $sql = new mysqli('localhost','root','password','dbname'); ?>Example of mysqli connection with the procedural method:
<?php $con = mysqli_connect('localhost','root','password','dbname'); ?>Connection error checking with object method:
<?php $sql = new mysqli('localhost', 'root', 'password', 'dbname'); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } ?>Connection error checking with procedural method:
<?php $con = mysqli_connect("HostName","UserName","password","DBName") or die("Some error occurred during connection " . mysqli_error($con)); ?>Simple procedure with complete code with procedural method:
<?php //Create the connection $con = mysqli_connect("HostName","UserName","password","DBName") or die("Some error occurred during connection " . mysqli_error($con)); // Write query $strSQL = "SELECT username FROM MyTable"; // Execute the query. $query = mysqli_query($con, $strSQL); while($result = mysqli_fecth_array($query)) { echo $result["username"]." "; } // Close the connection mysqli_close($con); ?>
No comments:
Post a Comment