Home > Database > Mysql Tutorial > body text

MySQL数据库函数详解(2)_MySQL

WBOY
Release: 2016-06-01 13:55:38
Original
852 people have browsed it

(6) int mysql_db_query(string db_name, string query [, int link_id]);

  mysql_db_query()除了提取一个额外的数据库名称参数,并在执行查询之前使它成为缺省的数据库为,与mysql_query()类似。

$link=mysql_pconnect("localhost","sunsoft","suixiang")
or die("Could not connect");

print("Connected successfully");

$query="SELECT * FROM president";

$result=mysql_db_query("samp_db",$query) or die("Query failed");


?>

(7) int mysql_drop_db(string db_name, int [link_id]);

   告诉由link_id标识的MySQL服务器用给定的名称来删除数据库。如果数据库删除成功,则返回真;如果出现错误,则返回假。必须有对数据库进行删除的DROP权限。

  要小心这个函数;如果删除数据库,它就不存在了,且不能恢复。

  使用mysql_query()较使用mysql_drop_db()发布DROP DATABASE 语句更为适合。

$link=mysql_pconnect("localhost","sunsoft","suixiang")
or die("Could not connect");

if(mysql_drop_db("my_db"))

print("Database dropped successfullyn");

else

printf("Error dropping database:%sn",mysql_error());

?>

(8) int mysql_errno(int [link_id]);

  对于给定的连接,返回含有最近返回状态的与MySQL相关的函数的错误号。零值意味着未出现错误。

使用范例

$link=mysql_pconnect("localhost","sunsoft","suixiang")
or die("Could not connect");

print("Connected successfully");

$query="SELECT * FROM president";

$result=mysql_query($query) or die("Query failed,error code=".mysql_errno());

?>

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!