


Analysis of solutions to the problem of inconsistent return values when calling stored procedures in PHP_php tips
The example in this article describes the solution to the problem of inconsistent return values when calling stored procedures in PHP. Share it with everyone for your reference, the details are as follows:
Today I met a classmate who was talking about the return value of a stored procedure and often got an unexpected value of null. Because I had something to do during the day, I did an experiment in the evening and put it here for students who have corresponding questions to check.
Stored procedure:
delimiter// createprocedureusp_s2(outpar1int) begin selectinet_ntoa(ip),portfromproxy_listlimit5; selectcount(*)intopar1fromproxy_list; END// delimiter;
session 1 execution:
mysql>callusp_s2(@a); +—————+——+ |inet_ntoa(ip)|port| +—————+——+ |1.34.21.86 |8088| |1.34.59.50 |8088| |1.34.69.15 |8088| |1.34.73.110 |8088| |1.34.76.218 |8088| +—————+——+ 5rowsinset(0.00sec) QueryOK,1rowaffected(0.01sec) mysql>select@a; +——+ |@a | +——+ |4430| +——+ 1rowinset(0.00sec)
session 2 execution:
mysql>select@a; +——+ |@a | +——+ |NULL| +——+ 1rowinset(0.00sec)
It can be seen that the results obtained by the two sessions are inconsistent. It is basically certain that two calls falling into different sessions will get different values.
For consistency, you can use the following call:
<?php $hostname="127.0.0.1"; $username="wubx"; $password="wubxwubx"; $database="proxydb"; $db=newmysqli($hostname,$username,$password,$database); if(mysqli_connect_errno()){ printf("Connect failed: %s\n",mysqli_connect_error()); exit(); } $result=$db->multi_query("call usp_s2(@total); select @total;"); if($result){ do{ if($r=$db->store_result()){ if($r->field_count==2){ while($row=$r->fetch_row()){ print"ip: $row[0], port: $row[1]\n"; } }else{ $row =$r->fetch_row(); print"total: $row[0]\n"; } } }while($db->next_result()); } $db->close(); ?>
$phpt_proc_return.php
ip:1.34.21.86,port:8088
ip:1.34.59.50,port:8088
ip:1.34.69.15,port:8088
ip:1.34.73.110,port:8088
ip:1.34.76.218,port:8088
total:4430
Good luck.
Readers who are interested in more PHP-related content can check out the special topics on this site: "MySQL stored procedure skills collection", "PHP data structure and algorithm tutorial", "Summary of PHP operations and operator usage", "Summary of PHP network programming skills", "PHP basic syntax introductory tutorial", "PHP operation office document Skills summary (including word, excel, access, ppt) ", "php date and time usage summary ", "php object-oriented programming introductory tutorial ", "Summary of php string (string) usage", "Introduction tutorial on php mysql database operation" and "Summary of common php database operation skills"
I hope this article will be helpful to everyone in PHP programming.

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



In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

PS "Loading" problems are caused by resource access or processing problems: hard disk reading speed is slow or bad: Use CrystalDiskInfo to check the hard disk health and replace the problematic hard disk. Insufficient memory: Upgrade memory to meet PS's needs for high-resolution images and complex layer processing. Graphics card drivers are outdated or corrupted: Update the drivers to optimize communication between the PS and the graphics card. File paths are too long or file names have special characters: use short paths and avoid special characters. PS's own problem: Reinstall or repair the PS installer.

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

A PS stuck on "Loading" when booting can be caused by various reasons: Disable corrupt or conflicting plugins. Delete or rename a corrupted configuration file. Close unnecessary programs or upgrade memory to avoid insufficient memory. Upgrade to a solid-state drive to speed up hard drive reading. Reinstalling PS to repair corrupt system files or installation package issues. View error information during the startup process of error log analysis.

In PHP, the final keyword is used to prevent classes from being inherited and methods being overwritten. 1) When marking the class as final, the class cannot be inherited. 2) When marking the method as final, the method cannot be rewritten by the subclass. Using final keywords ensures the stability and security of your code.

Frequently Asked Questions and Solutions when Exporting PS as PDF: Font Embedding Problems: Check the "Font" option, select "Embed" or convert the font into a curve (path). Color deviation problem: convert the file into CMYK mode and adjust the color; directly exporting it with RGB requires psychological preparation for preview and color deviation. Resolution and file size issues: Choose resolution according to actual conditions, or use the compression option to optimize file size. Special effects issue: Merge (flatten) layers before exporting, or weigh the pros and cons.

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.
