Connect to MySQL using MCPKit

Discussion in 'Mac Programming' started by Sergio10, Apr 24, 2009.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    hi,

    I want to connect MySQL database remotely using MCPKit framework:
    http://mysql-cocoa.sourceforge.net/

    I developed next:
    PHP:
        MCPResult *resuilt;
        
    NSString *campoX;
        
        
    MCPConnection *theConnec = [[MCPConnection allocinitToHost:@"localhost" 
                                                           
    withLogin:@"root" password:@"xxxx" usingPort:3303]; 
        
        if ([
    theConnec isConnected])
        {
            
    NSLog(@"Connected ");
        }
        else
        {
            
    NSLog(@"Not Connected ");
        }
        
        
    user = [[resuilt fetchRowAsArrayobjectAtIndex:1];
        
    NSLog(@"Valor: %@"campoX);
    I added framework to project. But when I compile source get errors. (XCode doesn't see MCPResult and MCPConnection).
    Why? How to fix this problem?
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    Firstly, are you including the source files for the framework somewhere in your source?? (aka using something like #import <MCPKit/MCPKit.h>)

    Secondly, I've never used these frameworks, but I think I spot some general Obj-C problems.

    NSString *campoX is never initialized, but you include it in the last NSLog. You didn't even init it as nil, so NSLog is going to pass it the message description, and you will throw an exception.

    MCPResult *resuilt is never initialized. I would PRESUME from everything in MySQL I've seen that there would be something SOMEWHERE after the connection that would look like...
    resuilt = [[MCPResult alloc] initWithConnection: theConnec andQuery: @"SELECT * FROM table WHERE .... you get the hint"];


    Generally in MySQL you need a connection, and then you make a query. What is returned is a funny array that you call MySQL functions on.
     
  3. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #3
    Thanks for replying. Do you have any suggestions how to connect to database in other way? Meybe using standard cocoa frameworks?
     
  4. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
  5. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #5
    So, I included
    And then got another error:
    How to fix this problem?
     
  6. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #6
    Can you post the contents of your source?

    Also, why is it named MyController.o?? Shouldn't it be .m? Thats how the compiler knows what to expect in the file. I hope thats the only problem.
     
  7. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #7
    That's just the object file.

    Most likely the problem is happening because the project isn't linking against the framework. Did you drag the framework into your project's Frameworks group? (And add it to a Copy Files build phase?)
     
  8. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #8
    I know what the .o means, but to the best of my knowledge when working with objective-c, your implementation should have .m at the end. I think this is for the compiler to know what language it is expecting in the file.
    Aren't .o files compiled objects or something?

    Was that warning a compiler warning, or a runtime error?
     
  9. Sergio10 thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #9
    Yes
     
  10. mahler4 macrumors newbie

    Joined:
    Dec 21, 2009
    Location:
    baltimore
    #10
    HELP-to install MCPKit framework

    HELP-to install MCPKit framework
    on http://mysql-cocoa.sourceforge.net/
    I Downloaded the framework --> MCPKit_src_3.0.1.dmg
    --> Documentation, MCP(AppKit,EntrepriseKit,FoundKit), MCPKit.xcodeproj, mysql-local
    There is no mySQL_bundled.framework, or --bundled
    Also, when I opened the project, missing are:
    MCPKit_bundled.framework,MCPKit_system.framework,
    MCPKit_FoundationTest,MCPKit_Prefix.pch,several things involving .plist

    Beginner-after install, would like examples of use of mysql
     
  11. ryanrhee90 macrumors newbie

    Joined:
    Jul 17, 2010
    #11
    Hi guys,

    I've written a detailed guide on how to add MCPKit to your xcode project.

    Hope that helps!
    -R
     

Share This Page