璇﹁Вphp璋冪敤MySQL瀛樺偍杩囩▼鏂规硶_PHP鏁欑▼ | 甯涔嬪
php涓巑ysql鏄ぉ鐢熺殑涓€瀵癸紝涓嬮潰鎴戞潵浠嬬粛鍦╬hp涓€庝箞璋冪敤mysql瀛樺偍杩囩▼骞舵墽琛岃繑鍥炵粨鏋滐紝涓嬮潰鎴戞€荤粨浜嗕竴浜涘父鐢ㄧ殑php璋冪敤MySQL瀛樺偍杩囩▼鐨勬柟娉曪紝鏈夐渶瑕佷簡瑙g殑鍚屽鍙弬鑰冦€?p>MySQL浠?.0寮€濮嬫墠寮曞叆瀛樺偍杩囩▼锛屽弽姝d互鍓嶅仛搴旂敤鐨勬椂鍊欎粠娌$杩囷紝涓嶈繃鐜板湪鍥犱负涓昏浣滃唴閮ㄧ郴缁燂紝鎵€浠ュ緢澶氬簲鐢ㄩ兘鐢ㄥ埌浜嗗瓨鍌ㄨ繃绋嬶紝褰撶劧鍓嶅彴鏈夋椂鍊欎篃闇€瑕佽皟鐢∕ySQL瀛樺偍杩囩▼锛孭HP鐨凪ySQL Lib濂藉儚鏀寔鐨勪笉鏄緢濂斤紝涓嶈繃鎴戞悳绱簡浜涜祫鏂欙紝铏界劧涓嶅锛屼絾鏄繕鏄皾璇曠殑浣跨敤浜嗭紝鐜板湪浠嬬粛涓€涓嬫柟娉?/p>
1銆傝皟鐢ㄥ瓨鍌ㄨ繃绋嬬殑鏂规硶銆?/p>
a銆傚鏋滃瓨鍌ㄨ繃绋嬫湁 IN/INOUT鍙傛暟锛屽0鏄庝竴涓彉閲忥紝杈撳叆鍙傛暟缁欏瓨鍌ㄨ繃绋嬶紝璇ュ彉閲忔槸涓€瀵癸紝涓€涓猵hp鍙橀噺锛堜篃鍙互涓嶅繀锛屽彧鏄病鏈塸hp鍙橀噺鏃讹紝娌℃湁鍔炴硶杩涜鍔ㄦ€佽緭鍏ワ級锛屼竴涓狹ysql鍙橀噺銆?/p>
b銆傚鏋滃瓨鍌ㄨ繃绋嬫湁OUT鍙橀噺锛屽0鏄庝竴涓狹ysql鍙橀噺銆俶ysql鍙橀噺鐨勫0鏄庢瘮杈冪壒娈婏紝蹇呴』璁﹎ysql鏈嶅姟鍣ㄧ煡閬撴鍙橀噺鐨勫瓨鍦紝鍏跺疄涔熷氨鏄墽琛屼竴鏉ysql璇彞銆傚叆set @mysqlvar=$phpvar ;
c銆備娇鐢╩ysql_query()/mysql_db_query()鎵цmysql 鍙橀噺澹版槑璇彞銆?/p>
浠g爜濡備笅 | 澶嶅埗浠g爜 |
mysql_query("set @mysqlvar銆?$pbpvar銆?quot;); |
杩欐牱锛屽湪mysql鏈嶅姟鍣ㄩ噷闈㈠氨鏈変竴涓彉閲忥紝@mysqlar銆傚鏋滄椂IN鍙傛暟锛岄偅涔堝叾鍊煎彲浠ユ湁phpar浼犲叆銆?/p>
d銆?濡傛灉鏃跺瓨鍌ㄨ繃绋嬨€?/p>
1銆傛墽琛?call procedure锛堬級璇彞銆?/p>
涔熷氨鏄痬ysql_query("call proceduer([var1]...)");
2. 濡傛灉鏈夎繑鍥炲€硷紝鎵цselect @ar锛岃繑鍥炴墽琛岀粨鏋溿€?/p>
浠g爜濡備笅 | 澶嶅埗浠g爜 |
mysql_query("select @var)" |
鎺ヤ笅鏉ョ殑鎿嶄綔灏卞拰php鎵ц涓€鑸殑mysql璇彞涓€鏍蜂簡銆傚彲浠ラ€氳繃mydql_fetch_row()绛夊嚱鏁拌幏寰楃粨鏋溿€?/p>
涓嬮潰鎴戞€荤粨浜嗕竴浜涜皟鐢ㄥ瓨鍌ㄨ繃绋嬬殑瀹炰緥鏃犲弬鐨勫瓨鍌ㄨ繃绋?/p>
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$sql = "call test.myproce();"; |
鍨嬩竴锛氳皟鐢ㄥ甫杈撳叆銆佽緭鍑虹被鍨嬪弬鏁扮殑鏂规硶
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$returnValue = ''; |
绫诲瀷浜岋細璋冪敤甯﹀涓緭鍑虹被鍨嬪拰澶氫釜杈撳叆绫诲瀷鍙傛暟鐨勬柟娉?/p>
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$userId = 0; |
绫诲瀷涓夛細璋冪敤甯﹁繑鍥炵粨鏋滈泦鐨勬柟娉?/p>
浠g爜濡備笅 | 澶嶅埗浠g爜 |
try { } catch ( Exception $e ) { |
绫诲瀷鍥涳細璋冪敤甯﹁繑鍥炲涓粨鏋滈泦鐨勬柟娉?鐩墠鍙兘閫氳繃mysqli鏉ュ疄鐜皛~)
浠g爜濡備笅 | 澶嶅埗浠g爜 |
//PHP |
瀹炰緥鍥涳細浼犲嚭鍙傛暟鐨刬nout瀛樺偍杩囩▼
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$sql = " create procedure myproce4(inout sexflag int) begin SELECT * FROM user WHERE sex = sexflag; end; "; mysql_query($sql);//鍒涘缓涓€涓猰yproce4鐨勫瓨鍌ㄨ繃绋?br /> $sql = "set @sexflag = 1"; mysql_query($sql);//璁剧疆鎬у埆鍙傛暟涓? $sql = "call test.myproce4(@sexflag);"; mysql_query($sql);//璋冪敤myproce4鐨勫瓨鍌ㄨ繃绋?鍦╟md涓嬮潰鐪嬫晥鏋?/td> |
瀹炰緥浜旓細浣跨敤鍙橀噺鐨勫瓨鍌ㄨ繃绋?/p>
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$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);//鍒涘缓涓€涓猰yproce5鐨勫瓨鍌ㄨ繃绋?br /> $sql = "call test.myproce5(4,6);"; mysql_query($sql);// |
璋冪敤myproce5鐨勫瓨鍌ㄨ繃绋?鍦╟md涓嬮潰鐪嬫晥鏋?/p>
瀹炰緥鍏細case璇硶
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$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);//鍒涘缓涓€涓猰yproce6鐨勫瓨鍌ㄨ繃绋?br /> $sql = "call test.myproce6(100);"; mysql_query($sql);// |
璋冪敤myproce6鐨勫瓨鍌ㄨ繃绋?鍦╟md涓嬮潰鐪嬫晥鏋?/p>
瀹炰緥涓冿細寰幆璇彞
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$sql = " create procedure myproce7() begin declare i int default 0; declare j int default 0; while i set j=j+i; set i=i+1; end while; select j; end; "; mysql_query($sql);//鍒涘缓涓€涓猰yproce7鐨勫瓨鍌ㄨ繃绋?br /> $sql = "call test.myproce7();"; mysql_query($sql);// |
璋冪敤myproce7鐨勫瓨鍌ㄨ繃绋?鍦╟md涓嬮潰鐪嬫晥鏋?/p>
瀹炰緥鍏細repeat璇彞
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$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);//鍒涘缓涓€涓猰yproce8鐨勫瓨鍌ㄨ繃绋?br /> $sql = "call test.myproce8();"; mysql_query($sql);// |
璋冪敤myproce8鐨勫瓨鍌ㄨ繃绋?鍦╟md涓嬮潰鐪嬫晥鏋?/p>
瀹炰緥涔濓細loop璇彞
浠g爜濡備笅 | 澶嶅埗浠g爜 |
$sql = " loop_label:loop |
璋冪敤myproce9鐨勫瓨鍌ㄨ繃绋?鍦╟md涓嬮潰鐪嬫晥鏋?/p>
瀹炰緥鍗侊細鍒犻櫎瀛樺偍杩囩▼
浠g爜濡備笅 | 澶嶅埗浠g爜 |
mysql_query("drop procedure if exists myproce");//鍒犻櫎test鐨勫瓨鍌ㄨ繃绋?/p> |
瀹炰緥鍗侊細瀛樺偍杩囩▼涓殑娓告爣

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content

Arrays are linear data structures used to process data in programming. Sometimes when we are processing arrays we need to add new elements to the existing array. In this article, we will discuss several ways to add elements to the end of an array in PHP, with code examples, output, and time and space complexity analysis for each method. Here are the different ways to add elements to an array: Use square brackets [] In PHP, the way to add elements to the end of an array is to use square brackets []. This syntax only works in cases where we want to add only a single element. The following is the syntax: $array[] = value; Example
