User login

shell

Upgrade between Drupal versions using a diff shell script

[This should be on its way to being obsoleted by drush, but i'm using it for Drupal 7 alpha so thought i'd finally make sure it was shared.]

Download this and other useful scripts from their public repository on gitorious.

(Please use the code from the repository, the below may be out of date.)

Running shell scripts

make file executable
chmod a+x scriptname

and don't forget to access as ./scriptname
rather than just scriptname

Resolution

In a shell script, create a database if it does not exist

Use the MySQL: SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'database_name'

<?php
if (mysql_num_rows(mysql_query("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '". $dbname ."'"))) {
  echo "Database $dbname already exists.";
}
else {
  // go on and create the user, database, etc.
  // create the user

  if (!mysql_query("CREATE USER '". $dbuser ."'@'%' IDENTIFIED BY '". $dbpass ."'"))  die(mysql_error());
  echo "User $dbuser created.\n";

Syndicate content