php与mysql使用存储过程
php如何调用mysql存储过程,以下十个小案例抛砖引玉:
实例一:无参的存储过程
$conn = mysql_connect('localhost','root','root') or die ("connect db fail!"); mysql_select_db('test',$conn); $sql = " create procedure myproce() begin INSERT INTO user (id, username, sex) VALUES (NULL, 's', '0'); end; "; mysql_query($sql);//创建一个myproce的存储过程 $sql = "call test.myproce();"; mysql_query($sql);//调用myproce的存储过程,则数据库中将增加一条新记录。
实例二:传入参数的存储过程
$sql = " create procedure myproce2(in score int) begin if score >= 60 then select 'pass'; else select 'no'; end if; end; "; mysql_query($sql);//创建一个myproce2的存储过程 $sql = "call test.myproce2(70);"; mysql_query($sql);//调用myproce2的存储过程,看不到效果,可以在cmd下看到结果。
实例三:传出参数的存储过程
$sql = " create procedure myproce3(out score int) begin set score=100; end; "; mysql_query($sql);//创建一个myproce3的存储过程 $sql = "call test.myproce3(@score);"; mysql_query($sql);//调用myproce3的存储过程 $result = mysql_query('select @score;'); $array = mysql_fetch_array($result); echo '<pre class="brush:php;toolbar:false">';print_r($array);
实例四:传出参数的inout存储过程
$sql = " create procedure myproce4(inout sexflag int) begin SELECT * FROM user WHERE sex = sexflag; end; "; mysql_query($sql);//创建一个myproce4的存储过程 $sql = "set @sexflag = 1"; mysql_query($sql);//设置性别参数为1 $sql = "call test.myproce4(@sexflag);"; mysql_query($sql);//调用myproce4的存储过程,在cmd下面看效果
实例五:使用变量的存储过程
$sql = " create procedure myproce5(in a int,in b int) begin declare s int default 0; set s=a+b; select s; end; "; mysql_query($sql);//创建一个myproce5的存储过程 $sql = "call test.myproce5(4,6);"; mysql_query($sql);//调用myproce5的存储过程,在cmd下面看效果
实例六:case语法
$sql = " create procedure myproce6(in score int) begin case score when 60 then select '及格'; when 80 then select '及良好'; when 100 then select '优秀'; else select '未知分数'; end case; end; "; mysql_query($sql);//创建一个myproce6的存储过程 $sql = "call test.myproce6(100);"; mysql_query($sql);//调用myproce6的存储过程,在cmd下面看效果
实例七:循环语句
$sql = " create procedure myproce7() begin declare i int default 0; declare j int default 0; while i<10 do set j=j+i; set i=i+1; end while; select j; end; "; mysql_query($sql);//创建一个myproce7的存储过程 $sql = "call test.myproce7();"; mysql_query($sql);//调用myproce7的存储过程,在cmd下面看效果
实例八:repeat语句
$sql = " create procedure myproce8() begin declare i int default 0; declare j int default 0; repeat set j=j+i; set i=i+1; until j>=10 end repeat; select j; end; "; mysql_query($sql);//创建一个myproce8的存储过程 $sql = "call test.myproce8();"; mysql_query($sql);//调用myproce8的存储过程,在cmd下面看效果
实例九:loop语句
$sql = " create procedure myproce9() begin declare i int default 0; declare s int default 0; loop_label:loop set s=s+i; set i=i+1; if i>=5 then leave loop_label; end if; end loop; select s; end; "; mysql_query($sql);//创建一个myproce9的存储过程 $sql = "call test.myproce9();"; mysql_query($sql);//调用myproce9的存储过程,在cmd下面看效果
实例十:删除存储过程
mysql_query("drop procedure if exists myproce");//删除test的存储过程
您可能感兴趣的文章
- mysql创建存储过程并在php中调用
- 用PHP函数memory_get_usage获取当前PHP内存消耗量以实现程序的性能优化
- php和mysql中uft-8中文编码乱码的几种解决办法
- php判断字符串是否全英文,纯中文,中英文组合的方法
- Mysql 数据库缓存cache功能分析,调试以及性能总结
- php和mysql中日期和unix时间戳的互相转换
- mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法
- php异步调试和线上调试网站程序的方法

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제









PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

MySQL 8.4(2024년 최신 LTS 릴리스)에 도입된 주요 변경 사항 중 하나는 "MySQL 기본 비밀번호" 플러그인이 더 이상 기본적으로 활성화되지 않는다는 것입니다. 또한 MySQL 9.0에서는 이 플러그인을 완전히 제거합니다. 이 변경 사항은 PHP 및 기타 앱에 영향을 미칩니다.

이 튜토리얼은 PHP를 사용하여 XML 문서를 효율적으로 처리하는 방법을 보여줍니다. XML (Extensible Markup Language)은 인간의 가독성과 기계 구문 분석을 위해 설계된 다목적 텍스트 기반 마크 업 언어입니다. 일반적으로 데이터 저장 AN에 사용됩니다

문자열은 문자, 숫자 및 기호를 포함하여 일련의 문자입니다. 이 튜토리얼은 다른 방법을 사용하여 PHP의 주어진 문자열의 모음 수를 계산하는 방법을 배웁니다. 영어의 모음은 A, E, I, O, U이며 대문자 또는 소문자 일 수 있습니다. 모음이란 무엇입니까? 모음은 특정 발음을 나타내는 알파벳 문자입니다. 대문자와 소문자를 포함하여 영어에는 5 개의 모음이 있습니다. a, e, i, o, u 예 1 입력 : String = "Tutorialspoint" 출력 : 6 설명하다 문자열의 "Tutorialspoint"의 모음은 u, o, i, a, o, i입니다. 총 6 개의 위안이 있습니다

숙련된 PHP 개발자라면 이미 그런 일을 해왔다는 느낌을 받을 것입니다. 귀하는 상당한 수의 애플리케이션을 개발하고, 수백만 줄의 코드를 디버깅하고, 여러 스크립트를 수정하여 작업을 수행했습니다.

PHP가 MySQL에 연결 한 후 페이지가 비어 있고 Die () 함수가 실패한 이유가 있습니다. PHP와 MySQL 데이터베이스 간의 연결을 배울 때는 종종 혼란스러운 것들이 발생합니다 ...

CMS는 콘텐츠 관리 시스템을 의미합니다. 사용자가 고급 기술 지식 없이도 디지털 콘텐츠를 생성, 관리 및 수정할 수 있는 소프트웨어 애플리케이션 또는 플랫폼입니다. CMS를 사용하면 사용자가 콘텐츠를 쉽게 생성하고 구성할 수 있습니다.
