mysqli Connect, Insert and Query data
// Build Connection with database.
$con = mysqli_connect("localhost","hkc","123","test_db");
// Database Connection checking with error numbers
if(mysqli_connect_error()){
echo "Connection Error Number is : ".mysqli_connect_errno();
}
// Specify values for enjoined fields of destination table.
Type 01 : $insert = "INSERT INTO test_table(name,roll,created_date) VALUES('Hasib',4153,NOW())";
Type 02 : $insert = "INSERT INTO test_table VALUES(null,'romel',4160,NOW())";
//Built Connection and send data into fields.
mysqli_query($con,$insert);
// Create Query
$query = mysqli_query($con,"SELECT * FROM test_table");
// To get few info by your query
print_r($query)
// Object oriented using this operator
$query->num_rows; [**num_rows found from print_r($query); ]
// Fetch data row by row, by using while loop
while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['roll']; ?></td>
<td><?php echo $row['created_date']; ?></td>
</tr>
<?php
}
$con = mysqli_connect("localhost","hkc","123","test_db");
// Database Connection checking with error numbers
if(mysqli_connect_error()){
echo "Connection Error Number is : ".mysqli_connect_errno();
}
// Specify values for enjoined fields of destination table.
Type 01 : $insert = "INSERT INTO test_table(name,roll,created_date) VALUES('Hasib',4153,NOW())";
Type 02 : $insert = "INSERT INTO test_table VALUES(null,'romel',4160,NOW())";
//Built Connection and send data into fields.
mysqli_query($con,$insert);
// Create Query
$query = mysqli_query($con,"SELECT * FROM test_table");
// To get few info by your query
print_r($query)
// Object oriented using this operator
$query->num_rows; [**num_rows found from print_r($query); ]
// Fetch data row by row, by using while loop
while ($row = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['roll']; ?></td>
<td><?php echo $row['created_date']; ?></td>
</tr>
<?php
}
Comments
Post a Comment