


Warning</b>: mysql_free_result(): supplied argument is not a valid MySQL result
这是什么错?
<?php header('content-type:application/json;charset=utf8'); $host = '127.0.0.1:3307'; $root = 'root'; $pwd = 'apeg1996'; $con = mysql_connect($host,$root,$pwd); if($con == false){ echo "连接数据库失败!"; }else{ echo "连接数据库成功!"; } $sql = "select * from user"; function execute_data($sql){ $result = mysql_query($sql); mysql_free_result($result); mysql_close($conn); return $result; } echo execute_data($sql);?>
已显示连接成功,但是报这个错。。
连接数据库成功!<br /><b>Warning</b>: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>F:\environment\WAMP\wamp5\wamp\wamp\www\test\sql.php</b> on line <b>17</b><br /><br /><b>Warning</b>: mysql_close(): supplied argument is not a valid MySQL-Link resource in <b>F:\environment\WAMP\wamp5\wamp\wamp\www\test\sql.php</b> on line <b>18</b><br />
回复讨论(解决方案)
$result = mysql_query($sql);
改为
$result = @mysql_query($sql) or die(mysql_error());
$result = mysql_query($sql);
改为
$result = @mysql_query($sql) or die(mysql_error());
网页上显示的是No database selected, 这个是没有找到这个数据库吗?
但是我用的是Navicat 8 for mysql 这个视图工具。
我在这里面创建的数据库,并简历了表。 我应该怎么去查询这个数据库里的表呢?
你只连接了数据库系统,但没有选择待操作的数据库
mysql_select_db('库名');
否则怎么知道你在查询那个库中的 user 表呢?
另外,你的 mysql_close($conn) 在函数中,而 $conn 并未传到函数中。
所以会有第2条错误
版主回答的完美
$result = mysql_query($sql);
改为
$result = @mysql_query($sql) or die(mysql_error());
网页上显示的是No database selected, 这个是没有找到这个数据库吗?
但是我用的是Navicat 8 for mysql 这个视图工具。
我在这里面创建的数据库,并简历了表。 我应该怎么去查询这个数据库里的表呢?
你在mysql_query之前没有mysql_select_db,mysql不知道你需要在哪个db中执行查询操作。
在创建连接后,加一句
@mysql_select_db(' 这里填写数据库名',$conn) or die(mysql_error());
<?php header('content-type:application/json;charset=utf8'); $host = '127.0.0.1:3307'; $root = 'root'; $pwd = 'apeg1996'; $con = mysql_connect($host,$root,$pwd); if($con == false){ echo "连接数据库失败!"; }else{ echo "连接数据库成功!"; } @mysql_select_db('这里填写数据库名',$conn) or die(mysql_error()); // 加入这句 $sql = "select * from user"; function execute_data($sql, $conn){ // 加入$conn 参数 $result = mysql_query($sql); mysql_free_result($result); mysql_close($conn); return $result; } echo execute_data($sql, $conn);?>

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

Alipay PHP...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
