search
Homephp教程php手册php 中使用return 出错

php 中使用return 出错

Jun 13, 2016 am 09:54 AM
mysqliphpreturnuseErrorexistAnswer




php 中使用return 出错
答案
在使用诸如mysqli_conn,只要有"i"的语句就会出错,我装的是php 最新版本.
在一个function中, 使用return $db, 也出错.
怎么回事?


最佳答案[url=http://www.phpchina.com/bbs/space.php?username=yafeikf]链接标记yafeikf[/url]
[url=http://www.phpchina.com/bbs/space.php?uid=38739]链接标记[img]http://www.phpchina.com/server/avatar.php?uid=38739&size=small[/img][/url]因为没打好基础。

mysql和mysqli均为MySQL For PHP的连接扩展。出错只有两个原因,1:根本就没有安装mysqli扩展;2:参数使用错误或数据库信息错误

你return的是什么。。假如一个function function a()

{

// function里是独立的一片天。function里根本就没有$db这个变量。你又从哪return的?

return $db;

}


复制代码



其它解决方案
因为没打好基础。

mysql和mysqli均为MySQL For PHP的连接扩展。出错只有两个原因,1:根本就没有安装mysqli扩展;2:参数使用错误或数据库信息错误

你return的是什么。。假如一个function function a()

{

// function里是独立的一片天。function里根本就没有$db这个变量。你又从哪return的?

return $db;

}


复制代码

其它解决方案
恩,我觉得可能是没打开扩展

其它解决方案
你把代码发出来啊
这样看很不清楚

其它解决方案
谢谢! 是mysqli没打开.
但return 还是出错.

function db_connect()
{
@ $db = mysqli_connect('localhost','root','8251617','bookmarks');
if (!$db)
{
throw new Exception('Could not connect to database server');
}
else
{
return $db;
echo 'dddd';
}
}

以上代码中,如去掉return 便可通过,但我需要return 值啊.
}

其它解决方案
[url=http://bbs.phpchina.com/redirect.php?goto=findpost&pid=1073261&ptid=128738]链接标记3#[/url] kazaff
谢谢你1

其它解决方案
return 之后的所有操作都不会继续执行

其它解决方案
[url=http://bbs.phpchina.com/redirect.php?goto=findpost&pid=1073310&ptid=128738]链接标记7#[/url] yafeikf
问题是:只要代码中有return就立马出http 500错,页面都找不到,跟之前的mysqli出同样的错,难道也有什么东西没打开?
谢谢

其它解决方案
是否装了Xdebug?
以后类似出错的问题,都可以通过它来追哈

其它解决方案
貌似代码有问题。。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.