Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    test for table created script

    Hi trying to create a simple setup script
    How do you test, if the table actually
    gets created or not?

    PHP Code:
    if($_POST['setup'] == 1) { 
    // connect...

    $table $_POST['prefix']."_MyTable";
    mysql_query("CREATE TABLE $table ( 
    id int(5) unsigned NOT NULL  AUTO_INCREMENT,
    PRIMARY KEY (id),
    test INT(11) NOT NULL)"
    );
    Print 
    "The table has been created";} 
    Thanks
    Sonny
    Last edited by sonny; 10-25-2012 at 11:11 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You would check the result of mysql_query. True would be successful.

  • Users who have thanked Fou-Lu for this post:

    sonny (10-25-2012)

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You would check the result of mysql_query. True would be successful.
    Hi
    Thought I tried something like that, ,but does not work, way you mention if not the same
    do not know how to implement that correctly
    PHP Code:
    $tableOK mysql_query("show tables like '$table'");
    if (
    $tableOK === true) echo "Table Created";
    else echo 
    "ERROR"
    Thanks
    Sonny

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    "show" returns a resultset; you cannot compare it identically to true. You need to check the results of the create table SQL.

  • #5
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    "show" returns a resultset; you cannot compare it identically to true. You need to check the results of the create table SQL.
    Hi does this look right? is this what you mean
    PHP Code:
    $table $_POST['prefix']."_MyTable";
    $queryOK mysql_query("CREATE TABLE IF NOT EXISTS $table ( 
    id int(5) unsigned NOT NULL  AUTO_INCREMENT,
    PRIMARY KEY (id),
    test INT(11) NOT NULL)"
    ); 

    if (
    $queryOK === true) echo "Table Created";
    else echo 
    "ERROR Table Not Created";} 

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep, that should do it. The docs don't specifically say that CREATE will return a true/false, but they do indicate that DROP does, so that would implicitly tell me that create does as well.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •