How to add fields in php

藏色散人
Release: 2023-03-05 14:26:01
Original
2756 people have browsed it

php method to add fields: first open the corresponding PHP file; then add fields through the "mysql_query("ALTER TABLE `article` ADD `keywords` varchar(100) NOT NULL default "")" method.

How to add fields in php

Recommended: "PHP Video Tutorial"

PHP operation MySQL adds a column (one field) to the table

For an already established database, the following methods can be used to add new fields to a table that already has fields:

mysql_query(“ALTER TABLE `表名` ADD `字段` 字段类型”) or die(mysql_error());
Copy after login

For example, add the field keywords to the table article

<?php
$link = mysql_connect($servername,$dbusername,$dbpassword);
if (mysql_select_db($dbname)) {
if ($link) {
echo “connect succeed”;
mysql_query("ALTER TABLE `article` ADD `keywords` varchar(100) NOT NULL default "") or die(mysql_error());
echo “Add succeed”;
} else {
echo “connect failed”;
}
mysql_close($link);
}
?>
Copy after login

Another: Use the keyword AFTER to add a new field after the current specific field (that is, insert a column between two columns)

The above is the detailed content of How to add fields in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!