php code to turn mysql auto commi off

Discussion in 'PHP' started by ianlufc, Apr 28, 2008.

  1. #1
    hey guys

    i am trying to turn autocommit off and use transactions but
    autocommit=0
    and
    autocomit=false

    aint working

    im using it on server2go

    anyone any ideas

    cheers
     
    ianlufc, Apr 28, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    It should be like this:

    
    $db = new mysqli(.....);
    $db->autocommit(FALSE);
    
    //do a bunch of queries...
    
    $db->commit();
    
    
    PHP:
    If you want to throw error handling in there I use this:

    
    
    if(!$db->commit()){
    					
    die($db->error);
    					
    }
    
    
    PHP:
    I think this may require using innodb storage so make sure you're not using myisam if you're still having problems.
     
    jestep, Apr 28, 2008 IP
  3. ianlufc

    ianlufc Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    do i have to install anything new to use mysqli?????

    appreciate this help man
     
    ianlufc, Apr 28, 2008 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    As long as the mysqli extension is enabled in the php build, then there is nothing else that needs to be done.

    Check your phpinfo(). There should be: "--with-mysqli=..." in the Configure Command.
     
    jestep, Apr 28, 2008 IP
  5. ianlufc

    ianlufc Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    mysqli
    MysqlI Support enabled
    Client API library version 5.0.22
    Client API header version 5.0.36
    MYSQLI_SOCKET /tmp/mysql.sock

    Directive Local Value Master Value
    mysqli.default_host no value no value
    mysqli.default_port 3306 3306
    mysqli.default_pw no value no value
    mysqli.default_socket no value no value
    mysqli.default_user no value no value
    mysqli.max_links Unlimited Unlimited
    mysqli.reconnect Off Off



    thats what i get from phpinfo()

    im building a shopping website for my final yr project in colege and had it all finished then i noticed i need a transaction for one part of it...its doing my head in.....cant even get it connected with mysqli........

    keep getting
    Warning: mysqli::mysqli() [function.mysqli-mysqli]: (HY000/2003): Can't connect to MySQL server on 'localhost' (10061) in C:*******\****\store\connect.php on line 11
    Connect failed: Can't connect to MySQL server on 'localhost' (10061)

    connect.php
    <?php
    /*
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("bookstore", $con);
    */
    ///////
    $mysqli = new mysqli("","","","bookstore");
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }
    ?>

    old connection is commented out

    cheers man
     
    ianlufc, Apr 28, 2008 IP