Solved

How to set default to "not null" when creating fields in phpmyadmin

Posted on 2006-11-09
9
591 Views
Last Modified: 2012-08-14
I'm using phpmyadmin to create the fields for an empty tablet.  For most of my fields I want to allow null values.  However, phpmyadmin always defaults to not null on the field creation screen.  Is there a fairly easy way to change this default?

I am currently using phpMyAdmin 2.6.3-pl1 and MySQL 4.1.13.

Since phpmyadmin is written in PHP, I suspect one could look through the code and fix this.  However, since this seem like something others might have wanted to do, I'm thinking maybe there is a configuration setting for phpmyadmin or someone has already figured out how to easily customize phpmyadmin's code to do this.
0
Comment
Question by:davidvieira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:kblack05
ID: 17908274
If you take a look at the documentation, there are settings in the PhPMyAdmin config to handle how it creates tables...

http://wiki.cihar.com/pma/Category:Configuration

The latest stable version is phpMyAdmin 2.9.1 so you might consider upgrading the software. I think that this issue might have been changed.
0
 
LVL 1

Author Comment

by:davidvieira
ID: 18039799
Shortly after making my original post I did up date phpMyAdmin to 2.9.1 and that did not address the issue.

I looked at the documentation you mention specifically concentrating on the Configuration Directives page at http://wiki.cihar.com/pma/Config and did not find the solution to my question.  However, that document was particularly user friendly so it is possible that I missed something buried there.

kblack05,

I also did not find any information that seemed directly related to how phpMyAdmin creates tables.  Could you refer me to a more specific place in the documentation?

Thanks.
0
 
LVL 11

Accepted Solution

by:
kblack05 earned 500 total points
ID: 18040569
In phpmyadmin directory is a file called tbl_create.php which contains some lib references, and also some create references. Chances are what you are attempting to do will require recoding this file, particularly the areas where these types of statements occur:

// Builds the 'create table' statement
    $sql_query      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $sql_query . ')';
    $query_cpy      = 'CREATE TABLE ' . PMA_backquote($table) . ' (' . $query_cpy . "\n" . ')';

    // Adds table type, character set and comments
    if (!empty($tbl_type) && ($tbl_type != 'Default')) {
        $sql_query .= ' ' . PMA_ENGINE_KEYWORD  . ' = ' . $tbl_type;
        $query_cpy .= "\n" . PMA_ENGINE_KEYWORD . ' = ' . $tbl_type;
    }
    if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_collation)) {
        $sql_query .= PMA_generateCharsetQueryPart($tbl_collation);
        $query_cpy .= "\n" . PMA_generateCharsetQueryPart($tbl_collation);
    }

    if (!empty($comment)) {
        $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
        $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
    }

    // Executes the query
    $error_create = false;
    $result    = PMA_DBI_try_query($sql_query) or $error_create = true;

    if ($error_create == false) {
        $sql_query = $query_cpy . ';';
        unset($query_cpy);
        $message   = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;

While I thought there was a config time option for this, it seems the public at large uses the default types in the creation, then uses the structure tool (tab) to modify any types.

0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 1

Author Comment

by:davidvieira
ID: 18634648
kblack05,

This is a little more complicated than I wanted to go at the moment, but thanks for the information.  I've accepted your answer and added it to my knowledge base for when I'm ready to try that.  

Maybe phpMyAdmin will add that as a config option before then.  :)

Thanks.
0
 
LVL 11

Expert Comment

by:kblack05
ID: 18634710
Sorry I wish there was a cleaner way. Perhaps there is another frontend you might consider. I think that there are some competitors to PhPMyAdmin which may work.

Looks like phpMyFlashAdmin has some interesting features, right on the front page it talks about default data structure options, though I have not used it.

http://www.bigwebmaster.com/2230.html
0
 
LVL 1

Author Comment

by:davidvieira
ID: 18659101
Thanks kblack05.  

I only read through the features list on the home page for phpMyFlashAdmin, but it looks like it might have the potential to replace Access in a database unit of a high-school class we teach here.  There is some interest in using mySQL instead of Access but for novices the graphical query and relationship tools in access are hard to beat.  If we could switch over to mySQL without loosing the simplicity we need for most students, it would be great for more advanced students who might be interested in doing something in PHP, which think is simpler than having to use VB or VBscript with an Access database. (I've done both some ADO programming in VB with access and PHP programming with mySQL.)
0
 
LVL 11

Expert Comment

by:kblack05
ID: 18663860
I believe that switching to mysql would be much more beneficial. It will be around long after MSAccess is no longer supported, and is constantly being updated. Agreed that the tools for Access are much more stylistic, and intutive for children to learn, which at the end of the day makes all the difference.

At one point there was a tool called "MySQLFront" http://www.mysqlfront.de/ but unfortunately someone decided the public did not have as much interest in ease of use as their pocketbook. :( This is a great example of what NOT to do in the open source world ). A replacement has come along which I know nothing about but may potentially investigate, which is called HeidiSQL http://www.heidisql.com/

Honestly I wish I had more answers and resources for you, sometimes the growth of Open Souce deals with pains caused by lack of attentiveness and greed. Overall it is my choice, and always will be, to advocate MySQL and other open source platforms such as Linux and FreeBSD. These software packages were built around performance, and gradually gravitate towards ease of use.

MS products are built with monetary return and ease of use in mind, and gradually gravitate towards availability based on affordability.

Perhaps in the not too distant future, the reality of the two will end up somewhere in between, though I always hope that it will be a free and unified open source world.
0
 
LVL 11

Expert Comment

by:kblack05
ID: 18663902
What do you know? HeidiSQL looks a lot like the MSAccess interface! In fact I think it has everything that MySQLFront had, and then some. Worth looking at.
0
 
LVL 1

Author Comment

by:davidvieira
ID: 18664444
Thanks!  I passed on the information to the teachers of the courses where Access is currently used.  The last three comments piggybacking on my original message is worth of a thread all it's own.  If I could grant you Expert's points for these recommendations too, I would.
0

Featured Post

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question