4 * Send SQL queries from the specified file to the database, performing
5 * variable replacement along the way.
8 require_once( dirname(__FILE__
) . '/' . 'commandLine.inc' );
10 if ( isset( $options['help'] ) ) {
11 echo "Send SQL queries to a MediaWiki database.\nUsage: php sql.php [<file>]\n";
15 if ( isset( $args[0] ) ) {
17 $file = fopen( $fileName, 'r' );
18 $promptCallback = false;
21 $promptObject = new SqlPromptPrinter( "> " );
22 $promptCallback = $promptObject->cb();
26 echo "Unable to open input file\n";
30 $dbw =& wfGetDB( DB_MASTER
);
31 $error = $dbw->sourceStream( $file, $promptCallback, 'sqlPrintResult' );
32 if ( $error !== true ) {
39 //-----------------------------------------------------------------------------
40 class SqlPromptPrinter
{
41 function __construct( $prompt ) {
42 $this->prompt
= $prompt;
46 return array( $this, 'printPrompt' );
49 function printPrompt() {
54 function sqlPrintResult( $res ) {
57 } elseif ( $res->numRows() ) {
58 while ( $row = $res->fetchObject() ) {
62 $affected = $res->db
->affectedRows();
63 echo "Query OK, $affected row(s) affected\n";