3 * Send SQL queries from the specified file to the database, performing
4 * variable replacement along the way.
7 * @ingroup Database Maintenance
10 require_once( dirname(__FILE__
) . '/' . 'commandLine.inc' );
12 if ( isset( $options['help'] ) ) {
13 echo "Send SQL queries to a MediaWiki database.\nUsage: php sql.php [<file>]\n";
17 if ( isset( $args[0] ) ) {
19 $file = fopen( $fileName, 'r' );
20 $promptCallback = false;
23 $promptObject = new SqlPromptPrinter( "> " );
24 $promptCallback = $promptObject->cb();
28 echo "Unable to open input file\n";
32 $dbw =& wfGetDB( DB_MASTER
);
33 $error = $dbw->sourceStream( $file, $promptCallback, 'sqlPrintResult' );
34 if ( $error !== true ) {
41 //-----------------------------------------------------------------------------
42 class SqlPromptPrinter
{
43 function __construct( $prompt ) {
44 $this->prompt
= $prompt;
48 return array( $this, 'printPrompt' );
51 function printPrompt() {
56 function sqlPrintResult( $res, $db ) {
59 } elseif ( is_object( $res ) && $res->numRows() ) {
60 while ( $row = $res->fetchObject() ) {
64 $affected = $db->affectedRows();
65 echo "Query OK, $affected row(s) affected\n";