-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_db.php
More file actions
25 lines (24 loc) · 767 Bytes
/
Copy pathprepare_db.php
File metadata and controls
25 lines (24 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$stderr = fopen( 'php://stderr', 'w' );
@list( $host, $port ) = explode( ':', $argv[1], 2 );
$maxTries = 10;
do {
$mysql = new mysqli( $host, $argv[2], $argv[3], '', (int) $port );
if ( $mysql->connect_error ) {
fwrite( $stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n" );
-- $maxTries;
if ( $maxTries <= 0 ) {
exit( 1 );
}
sleep( 3 );
}
} while ( $mysql->connect_error );
if (
! $mysql->query( 'DROP DATABASE IF EXISTS `' . $mysql->real_escape_string( $argv[4] ) . '`' ) ||
! $mysql->query( 'CREATE DATABASE `' . $mysql->real_escape_string( $argv[4] ) . '`' )
) {
fwrite( $stderr, "\n" . 'MySQL Query Error: ' . $mysql->error . "\n" );
$mysql->close();
exit( 1 );
}
$mysql->close();