简体   繁体   English

嵌套在if语句中的MySQL查询-PHP

[英]MySQL query nested in an if statement - PHP

Can a MySQL query string be nested inside an if statement as shown below? MySQL查询字符串是否可以嵌套在if语句内,如下所示?

if (mysql_query($queryString)) {
    return true;
}
else {
    return $error;
}

If this is not possible, what is the best way to make sure that the query has been executed by the query that is inside the if statement? 如果这不可能,那么确保该查询已由if语句内部的查询执行的最佳方法是什么?

(I know that MySQL has been depreciated now, but to change it across the site that I am building would be far to difficult and long-winded) (我知道MySQL现在已经贬值了,但是要在我正在构建的站点上对其进行更改将是困难而漫长的)

Yes it depends on the what kind of statement you're doing 是的,这取决于您正在执行哪种声明

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. 对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回结果集的语句,mysql_query()成功时返回资源,错误时返回FALSE。

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. 对于其他类型的SQL语句,例如INSERT,UPDATE,DELETE,DROP等,mysql_query()成功返回TRUE,错误返回FALSE。

http://php.net/manual/en/function.mysql-query.php http://php.net/manual/en/function.mysql-query.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM