Solved

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

Posted on 2006-11-09
9
587 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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