Home > php教程 > php手册 > body text

php执行sql语句的写法

WBOY
Release: 2016-06-13 12:24:38
Original
1874 people have browsed it

复制代码 代码如下:


@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
$query = @mysql_query("select * from tablename1") //执行SQL语句
or die("SQL语句执行失败");
?>



复制代码 代码如下:


@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
$query = @mysql_query("insert into tablename1 values('4', 'Judy','456')")
or die("SQL语句执行失败");
?>



复制代码 代码如下:


@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
$query = @mysql_query("select * from tablename1") //执行SQL语句
or die("SQL语句执行失败");
echo mysql_result($query, 0, 'username'); //输出第0行的name列
?>

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 Recommendations
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!