Logar Erros PHP

1 – Altere as entradas abaixo em /etc/php.ini

log_errors = On
error_log = /var/log/php_errors.log

2 – Teste

php -r "error_log('123');"
more /var/log/php_errors.log

3 – Adicionando entrada ao logrotate ( opcional )

vi /etc/logrotate.d/php-cli

/var/log/php_errors.log {
  weekly
  missingok
  rotate 13
  compress
  delaycompress
  copytruncate
  notifempty
  create 664 root www-users
  sharedscripts
}

Script para Exportar usuarios e permissoes MySQL

<?php
// Exporta usuarios e permissoes MySQL

$host = 'localhost';
$user = 'root';
$pass = 'toor';

header('Content-type: text/plain; Charset=UTF-8');
$export = array();
$link = new mysqli($host, $user, $pass, 'mysql', 3306);

if ($link->connect_error) {
printf('Connect failed (%s): %s', $link->connect_errno, $link->connect_error);
die();
}

$link->query('SET NAMES \'utf8\'');
$result = $link->query('SELECT `User`, `Host`, `Password` FROM `user`');

if ($result) {
while ($row = $result->fetch_row()) {
$user = $row[0];
$host = $row[1];
$pass = $row[2];

$export[] = 'CREATE USER `'. $user .'`@`'. $host .'` IDENTIFIED BY \''. $pass .'\'';

// Fetch any permissions found in database
$result2 = $link->query('SHOW GRANTS FOR `'. $user .'`@`'. $host .'`');

if ($result2) {
while ($row2 = $result2->fetch_row()) {
$export[] = $row2[0];
} // while ($row2...
} // if ($result2)...
} // while ($row...
}

$link->close();
echo implode(";\n", $export);
?>

 

Conexão com MariaDB usando PHP 7

// Connecting, selecting database
$mysqli = new mysqli('192.168.100.188', 'user', 'password', 'database');

// Check erros
if ( $mysqli->connect_errno ) {
  echo $mysqli->connect_errno, ' ', $mysqli->connect_error;
}

// SQL query
$sql = 'SELECT Host, User, Password FROM user';

// Printing results
$result = $mysqli->query( $sql );

while ( $row = $result->fetch_assoc() ) {
  echo $row['Host'], ' ', $row['User'], ' ', $row['Password'], "\n";
}

// Close Connection
$mysqli->close();