Skip to content

Instantly share code, notes, and snippets.

@itssalman
Created April 24, 2015 14:04
Show Gist options
  • Save itssalman/63c659be5eedc32e22a5 to your computer and use it in GitHub Desktop.
Save itssalman/63c659be5eedc32e22a5 to your computer and use it in GitHub Desktop.
PHP : MySQLI
<?php
/**
* Created by PhpStorm.
* User: SALMAN ASLAM
* Date: 12-Jan-15
* Time: 10:26 PM
*/
// create connection
$mysqli = new mysqli('localhost','root','salman','company');
// check connection
if(mysqli_connect_errno())
{
print_f("Connection not successful %s\n".mysqli_connect_errno());
}
$result = $mysqli->query("SELECT * FROM employees");
?>
<h1>Employees</h1>
<table width="500px" cellpadding="5" cellspacing="5" border="1">
<tr>
<th>ID#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Email</th>
</tr>
<?php while($row = $result->fetch_object()): ?>
<tr>
<td><?php echo $row->id; ?></td>
<td><?php echo $row->first_name; ?></td>
<td><?php echo $row->last_name; ?></td>
<td><?php echo $row->department; ?></td>
<td><?php echo $row->email; ?></td>
</tr>
<?php endwhile;?>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment