PHP Operation MySQL Summary

Source: Internet
Author: User

<?php
02
$dbhost = ' localhost ';
03
$dbuser = ' root ';
04
$dbpass = ' 123456 ';
05
$dbname = ' products ';
06
$connect =mysql_connect ($dbhost, $dbuser, $dbpass);
07
if (! $connect) exit (' Database connection failed! ‘);
08
mysql_select_db ($dbname, $connect);
09
mysql_query (' Set names UTF8 ');
10
Inquire
11
$sql = "SELECT * from ' Category '";
12
$result =mysql_query ($sql);
13
while ($row =mysql_fetch_array ($result)) {
14
echo $row [' id '];
15
}
16
Insert
17
$sql = "INSERT into ' category ' (' id ', ' name ') VALUES (NULL, '". $name. "')";
18
$result =mysql_query ($sql);
19
if (Mysql_affected_rows ()) {
20
Echo ' Insert succeeded, insert ID: ', mysql_insert_id ();
21st
}else{
22
Echo ' Insert failed: ', mysql_error ();
23
}
24
Modify
25
$sql = "UPDATE ' category ' SET ' name ' = '". $name. "' WHERE ' id ' = ' ". $id." ' ";
26
$result =mysql_query ($sql);
27
if (Mysql_affected_rows ()) {
28
Echo ' modified successfully! ‘;
29
}
30
Delete
31
$sql = "DELETE from ' category ' WHERE ' id ' = '". $id. "'";
32
$result =mysql_query ($sql);
33
if (Mysql_affected_rows ()) {
34
Echo ' Delete succeeded! ‘;
35
}
36
Close connection
37
Mysql_close ($connect);

PHP Operation MySQL Summary

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.