MySQL数据库函数详解(1)

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

在给定的连接中,返回由最近的DELETE、INSERT、REPLACE或者UPDATE语句所作用的行数。如果没有行

被修改,则MySQL_affected_rows()返回0,如果出现错误,则返回-1。
在SELECT查询之后,MySQL_affected_rows()返回所选择的行数。但一般是与SELECT语句一道使用

MySQL_num_rows().

使用范例:
<?php
$link=MySQL_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
MySQL_select_db("samp_db") or die("Could not select database");
$query="INSERT INTO

member(last_name,first_name,expiration)"."VALUES('Brown','Marcia','2002-6-3')";
$result=MySQL_query($query) or die("Query failed");
printf("%d row%s insertedn",MySQL_affected_rows(),MySQL_affected_rows()==1?" ":"s");
?>


(2) int MySQL_close(int[link_id]);
关闭由link_id标识的与MySQL服务器的连接。如果没有指定连接,则MySQL_close()关闭最近打开的连

接。如果成功,则MySQL_close()返回真,失败则返回假。对由MySQL_pconnect()打开的永久连接,

MySQL_close()忽略相应的关闭请求,只是返回值。如果要关闭一个连接,就应该用MySQL_connect()而不是

MySQL_pconnect()来打开它。

使用范例:

<?php
$link=MySQL_connect("localhost","sunsoft","suixiang") or die("Could not connect");
print("Connected successfully");
MySQL_close($link);
?>


(3) int MySQL_connect(string [hostname] [:port], string [username], string [password]);
本函式建立与 MySQL 伺服器的连线。其中所有的参数都可省略。当使用本函式却不加任何参数时,参

数 hostname 的内定值为 localhost、参数 username 的内定值为 PHP 执行行程的拥有者、参数 password 则

为空字串 (即没有密码)。而参数 hostname 后面可以加冒号与埠号,代表使用那个埠与 MySQL 连接。当然在

使用资料库时,早点使用 MySQL_close() 将连线关掉可以节省资源。


使用范例


这是一位未具名网友提供的范例 (18-Feb-1999)
<?php
$dbh = MySQL_connect('localhost:3306','mcclain','standard');
MySQL_select_db('admreqs');
$query = "insert into requests(date, request, email, priority,status) values

(NOW(),'$description', '$email', '$priority', 'NEW')";
$res = MySQL_query($query, $dbh);
$query = "select max(id) from requests";
$res = MySQL_query($query, $dbh);
$err = MySQL_error();
if($err){
echo "发生错误,请通知<a href=mailto:webmaster@my.site>站长</a>";
}
$row = MySQL_fetch_row($res);
echo "未来您使用的号码为: ".$row[0];
?>


(4) int MySQL_create_db(string db_name [, int link_id]);
告诉由link_id标识的MySQL服务器用给定的名称来创建数据库。如果数据库创建成功,则返回真;如

果出现错误,则返回假。必须在数据库有创建它的CREATE权限。
可能利用MySQL_query()较利用MySQL_create_db()发布CREATE DATABASE 语句更为适合。
<?php
$link=MySQL_pconnect("localhost","sunsoft","suixiang"); or die("Could not connect");
if(MySQL_create_db("my_db"))
print("Database created successfullyn");
else
print("Error creating database:%sn",MySQL_error());
?>
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值