CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2009
    Location
    California
    Posts
    31

    php - problem with setting up mysql db/table

    Im having the most frustrating time trying to figure this out, this script runs great on my private (WAMP) server but not on my hosting server (LAMP). The script is pretty simple, creates a database with a table of 6 fields:
    Code:
    <?php
    
    $host = "127.0.0.1";
    $username = "my_username";
    $pwd = "my_password";
    
    if (mysql_connect($host, $username, $pwd))
    {
    	$query = "CREATE DATABASE IF NOT EXISTS weup";
    	//execute query
    	if (mysql_query($query))
    	{
                print "Database created successfully!<br />";
                //must select db before creating table
                if (@mysql_select_db("weup"))
                {
                   $query = "CREATE TABLE IF NOT EXISTS applications(appname VARCHAR(25), 
     description VARCHAR(200), applink VARCHAR(50), authname VARCHAR(50), authage INT, authloc VARCHAR(40))";
                    //create the table
                    if (mysql_query($query)) print "Table created successfully!";
                    else print "Error creating table";
                }
    	} else print "Error creating database";
    	mysql_close();
    } else print "Unable to connect to " . $host;
    
    ?>

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: php - problem with setting up mysql db/table

    You haven't stated which part of it fails.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2009
    Location
    California
    Posts
    31

    Re: php - problem with setting up mysql db/table

    oh im sorry. specifically the 'mysql_query($query)' is whats not working. I know the actual string is good so am i executing it wrongly?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: php - problem with setting up mysql db/table

    Which one?

    Also...you have a @ in front of mysql_select_db(). That tells it to suppress errors. You might not get a good log report that way.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Nov 2009
    Location
    California
    Posts
    31

    Re: php - problem with setting up mysql db/table

    both of them, so right now i'm getting outputted "error creating database". and if i take out that first "if(mysql_query())" and just have "mysql_query", then on the next query i get "Error creating table". so basically both
    Code:
    if (mysql_query($query))
    are coming back negative.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: php - problem with setting up mysql db/table

    So copy the exact query string into phpMyAdmin. See what that returns.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Nov 2009
    Location
    California
    Posts
    31

    Re: php - problem with setting up mysql db/table

    hey guys, thanks for the replies. after running it through phpMyAdmin I realized the problem had to do with my hosting server not the code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured