mysql 不同步存储过程_php – MySQL存储过程导致`命令不同步’

调用程序在MySQL终端中可以正常工作,但在PHP中,导致命令不同步;你不能运行这个命令nowCommands不同步;你现在不能运行这个命令

我的程序是

delimiter $$

create procedure getMostSimilar (IN vU_ID INT, IN voffset INT, IN vsize INT)

BEGIN

set @offset = voffset;

set @size = vsize;

set @uid = vU_ID;

prepare SimilarStmt from

"SELECT U_ID, getSimilarity(U_ID, ?) AS similar FROM Answer WHERE U_ID != ? GROUP BY U_ID ORDER BY similar DESC LIMIT ?, ?";

execute SimilarStmt using @uid, @uid, @offset, @size;

deallocate prepare SimilarStmt;

END

$$

其中getSimilarity是一个函数.

在PHP中:

function getMostSimilar($U_ID, $offset, $size){

$query = sprintf("CALL getMostSimilar(%s, %s, %s)",

$U_ID, $offset, $size);

$result = mysql_query($query);

print mysql_error();

if (!$result){

return $query;

}

$ans = array();

$len = 0;

while($row = mysql_fetch_assoc($result)){

$ans[$len] = $row;

$len++;

}

return $ans;

}

我现在应该怎么做?谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基本的 PHP 代码示例,可以将本地 MySQL 数据库中的数据同步到微信小程序云存储中: ```php <?php // 连接本地 MySQL 数据库 $conn = mysqli_connect("localhost", "username", "password", "database_name"); if (!$conn) { die("连接失败: " . mysqli_connect_error()); } // 查询本地 MySQL 数据库中的数据 $sql = "SELECT * FROM table_name"; $result = mysqli_query($conn, $sql); // 将查询结果存储到数组中 $data = array(); while ($row = mysqli_fetch_assoc($result)) { $data[] = $row; } // 关闭 MySQL 连接 mysqli_close($conn); // 同步数据到微信小程序云存储 $appid = "your_appid"; $secret = "your_secret"; $collection = "your_collection"; $url = "https://api.weixin.qq.com/tcb/databaseadd?access_token="; $access_token = getAccessToken($appid, $secret); // 获取 access_token if ($access_token) { $data_json = json_encode($data, JSON_UNESCAPED_UNICODE); // 将数据转换为 JSON 格式 $url .= $access_token; $data = array( "env" => "your_env", "query" => "db.collection(\"{$collection}\").add({data: {$data_json}})" ); $result = httpRequest($url, $data); // 发送 HTTP 请求 if ($result["errcode"] == 0) { echo "数据同步成功"; } else { echo "数据同步失败: " . $result["errmsg"]; } } else { echo "获取 access_token 失败"; } // 获取 access_token function getAccessToken($appid, $secret) { $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $result = httpRequest($url); if ($result["access_token"]) { return $result["access_token"]; } else { return false; } } // 发送 HTTP 请求 function httpRequest($url, $data = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($data) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); } $result = curl_exec($ch); curl_close($ch); return json_decode($result, true); } ``` 注意修改代码中的以下参数: - `username`、`password`、`database_name`:MySQL 数据库的连接信息; - `table_name`:要同步的数据表名称; - `your_appid`、`your_secret`:微信小程序的 AppID 和 AppSecret; - `your_env`:云开发环境 ID; - `your_collection`:要同步到的集合名称。 此外,你还需要在微信小程序云开发控制台中创建相应的集合,并在云函数中引入该 PHP 文件并调用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值