简体   繁体   中英

MySQL query nested in an if statement - PHP

Can a MySQL query string be nested inside an if statement as shown below?

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?

(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)

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.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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