1

I want to run 2 queries in one statement in a PHP page. First query converts the datetime to greek, especially the day.

$query displays the table in my page.

They work as 2 queries in my joomla plesk, mysql database with a delimiter. But not in PHP.

Query I want to implement, before the main query:

SET lc_time_names = 'el_GR'
$query = "SELECT start,DATE_FORMAT(registerdate,'%W %d %M %Y') AS registerdate FROM table1;"  

$query2 = "SET lc_time_names = 'el_GR'"

I want it to run set lc time first, and then the query to display register date column. Can I do that in a single query, or 2 queries?

Regards.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Seems to me you would be better to get the data from the database as it is and then using the [DateTime class](http://php.net/manual/en/ref.datetime.php) in your presentation layer to format the date according to local requirements – RiggsFolly Feb 01 '18 at 09:36

1 Answers1

0

You can do it in PHP too.

Take look at multiple statements in the PHP manual

Here is what your PHP code should look like:

$query = "setlocale(LC_TIME, 'el_GR.UTF-8');
          SELECT start,
                 DATE_FORMAT(registerdate,'%W %d %M %Y') AS registerdate 

          FROM table1;";

$mysqli = new mysqli("example.com", "user", "password", "database");

if (!$mysqli->multi_query($query)) {
echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

do {
if ($res = $mysqli->store_result()) {
    var_dump($res->fetch_all(MYSQLI_ASSOC));
    $res->free();
}
} while ($mysqli->more_results() && $mysqli->next_result()); 
kiks73
  • 3,718
  • 3
  • 25
  • 52