使用mysql_fetch_array函數(shù)即可:如:$query="SELECT * FROM member_friends WHERE mid = ";
成都創(chuàng)新互聯(lián)公司主營賓縣網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),賓縣h5小程序制作搭建,賓縣網(wǎng)站營銷推廣歡迎賓縣等地區(qū)企業(yè)咨詢
$result=mysql_fetch_array(mysql_query($query));
print_r($result);exit;
$pdo = new PDO('mysql:host=localhost;dbname=','root','');
$data = $pdo-query('SELECT * FROM `user`');
foreach($data as $v){
echo $v['id'];
}
正常情況下你還應(yīng)該處理異常
try{
$pdo = new PDO('mysql:host=localhost;dbname=','root','');
$data = $pdo-query('SELECT * FROM `user`');
foreach($data as $v){
print_r($v);
}
}catch(PDOException $e){
}
代碼如下:
CREATE function Get_StrArrayStrOfIndex
(
@str varchar(1024), --要分割的字符串
@split varchar(10), --分隔符號
@index int --取第幾個元素
)
returns varchar(1024)
as
begin
declare @location int
declare @start int
declare @next int
declare @seed int
set @str=ltrim(rtrim(@str))
set @start=1
set @next=1
set @seed=len(@split)
set @location=charindex(@split,@str)
while @location0 and @index@next
begin
set @start=@location+@seed
set @location=charindex(@split,@str,@start)
set @next=@next+1
end
if @location =0 select @location =len(@str)+1
--這兒存在兩種情況:1、字符串不存在分隔符號 2、字符串中存在分隔符號,跳出while循環(huán)后,@location為0,那默認為字符串后邊有一個分隔符號。
return substring(@str,@start,@location-@start)
end
運行效果:
調(diào)用示例:select dbo.Get_StrArrayStrOfIndex('8,9,4',',',2)
返回值:9
親,如果你的返回結(jié)果集不是一條記錄的話,需要循環(huán)獲得,你直接while($row
=
$mysql_fetch_array($result)){
$data[]=$row;
}
就行了。
mysql中要獲得存儲過程的返回值,可以增加一個out參數(shù),用來返回。
mysql中存儲過程的例子:
CREATE PROCEDURE addvoucher (
IN userid INT,
IN voucherid INT,
OUT?result INT
)
BEGIN
SELECT
@endate_a := endate ,@batch_a := batch ,@c_count_a := c_count,
@isdead_a := isdead
FROM
t_voucher
WHERE
id = voucherid;
SET autocommit = 0;
IF EXISTS (
SELECT
*
FROM
t_user_voucher tuv,
t_voucher tv
WHERE
tv.id = tuv.voucherid
AND tv.batch =@batch_a
) THEN
SET result = 1;-- 已存在
SELECT
result;
ELSE
IF @c_count_a 0 THEN
IF (
TO_DAYS(@endate_a) - TO_DAYS(NOW())
) 0 THEN
IF @isdead_a = 1 THEN
INSERT INTO t_user_voucher (userid, voucherid, isdead)
VALUES
(userid, voucherid, 1);
UPDATE t_voucher SET c_count = c_count-1 where id = voucherid;
SET result = 0;-- 成功
END;
下面是調(diào)用并返回結(jié)果: