Skip to content
PHP Logo

What is the correct syntax for the CURDATE() function in MySQL queries in PHP?

When using the CURDATE() function in MySQL queries in PHP, it should be used within the SQL query string and not concatenated as a PHP variable. This is because CURDATE() is a MySQL function and should be executed within the database query itself.

php
// Incorrect way of using CURDATE()
$query = "SELECT * FROM table WHERE date = '" . CURDATE() . "'";
```

To correctly use CURDATE() in MySQL queries in PHP, simply include it directly in the SQL query string like this:

```php
// Correct way of using CURDATE()
$query = "SELECT * FROM table WHERE date = CURDATE()";