2 回答
TA贡献1772条经验 获得超6个赞
您可以尝试如下操作:
HTML:
<input type='button' value='Call Procedure' id='BtnId'>
jQuery的:
$(document).ready(function(){
$("#BtnId").on( 'click', function(){
$.ajax({
type : "POST",
url : "callsp.php",
success : function(text){
alert(text);
}
});
return false;
});
});
PHP: (callsp.php)
<?php
// connect to database
$connection = mysqli_connect("hostname", "username", "password", "db", "port");
// run the query
$result = mysqli_query($connection, "CALL DeleteRow") or die("Query Failed: " . mysqli_error());
// loop the result set
while( $row = mysqli_fetch_array($result) ) {
print_r( $row );
}
?>
TA贡献1921条经验 获得超9个赞
假设您的存储过程类似
DELIMITER $$
CREATE PROCEDURE getDetails()
BEGIN
SELECT * FROM tablename;
END$$
现在,您可以通过以下方式执行此操作 PHP
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
// execute the stored procedure
$sql = 'CALL getDetails()';
// call the stored procedure
$q = $pdo->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Error occurred:" . $e->getMessage());
}
while ($r = $q->fetch()){
/*
* Do something
*/
}
单击时,您可以实施Ajax以使其正常运行。您可以按照PHP Ajax示例
- 2 回答
- 0 关注
- 257 浏览
添加回答
举报