php-创建表

HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


    
    charset="UTF-8">


    //连接服务器并选中数据库:
    if($dbc = @mysql_connect('localhost','username','password')){
        //如果数据库无法选中,打印错误信息:
        if(!@mysql_select_db('myblog',$dbc)){
            echo '

Could not select the database because:
'. mysql_error($dbc).'.

'
; mysql_close($dbc); $dbc = FALSE; } }else{ //连接失败。 echo '

Could not connect to MySQL:
'.mysql_error(). '.

'
; } if($dbc) { //定义查询: $query = 'CREATE TABLE entries( entry_id INT NUSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, entry TEXT NOT NULL, date_entered DATETIME NOT NULL )'; //执行查询: if(@mysql_query($query,$dbc)){ echo '

The table has been created!

'
; }else{ echo '

Could not create the table because:
'. mysql_error($dbc).'.

The query being run was:'.$query.'

'
; } mysql_close($dbc); //关闭连接。 } ?>

你可能感兴趣的:(php-创建表)