Solved

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

Posted on 2006-11-09
9
583 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now