I want to run a script only once on a ‘thank you’ page

You can use order post meta to check order already there or not. try below code. let me know if this helps you.

$order_id = $order->get_id();
$fbpixel = get_post_meta($order_id, 'fbpixel-'.$order->get_order_number(),true);
if ( $order->get_subtotal() > 0 && ( empty( $fbpixel ) ) ) : 
  update_post_meta($order_id, 'fbpixel-'.$order->get_order_number(),1);
  ?>
  <script>
      fbq('track', 'Purchase', {currency: "AUD", value: <?php echo ($order->get_total() - $order->get_total_shipping()); ?> });
  </script>
<?php endif;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)