Can't update mysql database from PHP5

Discussion in 'PHP' started by KShum, May 7, 2007.

  1. #1
    I recently upgraded to Apache 2.2. As a result I upgraded to PHP5 and in the process, upgraded to the latest version mysql. I now cannot create a new database in mysql from PHP. Has anyone else encountered this problem? Below is the code I am using to create a database.

    <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'password';
    $dbname = 'newdb';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
    ('Error connecton to mysql');

    $query = "CREATE DATABASE newdb";
    $result = mysql_query($query);

    mysql_select_db('newdb');

    mysql_close($conn);
    ?>​
    I get no errors, but when I check within mysql, the new database has not been created. Your help would be greatly appreciated. I have no idea where to start since I am getting no error messages.
     
    KShum, May 7, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Replace:
    
    $result = mysql_query($query);
    
    PHP:
    With:
    
    $result = mysql_query($query) OR die(mysql_error());
    
    PHP:

    And see what error you get. You may have to restore the privileges.
     
    nico_swd, May 7, 2007 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    By 'latest version of MySQL', do you mean MySQL5?

    I think you need to use the mysqli_ functions for that, though could be wrong. nico_swd's right, either way, though I would also suggest replacing "die
    ('Error connecton to mysql');" with "die(mysql_error());", too.

    It's silly not giving PHP and MySQL the chance to actually tell you what went wrong :)
     
    TwistMyArm, May 7, 2007 IP
  4. KShum

    KShum Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I tried both suggestions and still no errors are displayed and no database is created. Any other ideas?

    TwistMyArm - I have never used mysqli_functions. Where do I find out more about them?
     
    KShum, May 7, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    nico_swd, May 8, 2007 IP