PHP MySQL operation

Source: Internet
Author: User

<table width= "100%" border= "1" cellpadding= "0" cellspacing= "0" >

<tr>
<td> Code </td>
<td> name </td>
<td> Sex </td>
<td> ethnic </td>
<td> Birthdays </td>
</tr>

<?php

1. Create a Mysqli object, create a Connection object
$db = new mysqli ("localhost", "username", "password", "database Name");

2. Prepare an SQL statement
$sql = "SELECT * from Info";

3. Execute the SQL statement and, if it is a query statement, successfully return the result set object
$reslut = $db->query ($sql);

4. Determine if the return execution was successful
if ($reslut)
{
while ($attr = $reslut->fetch_row ())
{
echo "<tr>
<td>{$attr [0]}</td>
<td>{$attr [1]}</td>
<td>{$attr [2]}</td>
<td>{$attr [3]}</td>
<td>{$attr [4]}</td>
</tr> ";
}

}

?>

</table>

Fetch_all () returns all arrays

Fetch_row () returns an indexed array

FETCH_ASSOC () returns an associative array

Fetch_object () returns the object

Fetch_array () returns an array of both indexed and associated

Database Delete, add, modify operation

<?php

Connecting objects
$db = new mysqli ("localhost", "username", "password", "database Name");

Preparing SQL statements
$sql = "Delete from info where code= ' p004 '"; Delete

$sql = "Insert Course values" increment

$sql = "Update table name set field = information where field = info" Change

Execute SQL statement
$r = $db->query ($sql);

if ($r)
{
echo "Successful execution";
}
Else
{
echo "Failed to execute";
}


?>

PHP MySQL operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.