Jump to content

creating tables help


pixeltrace

Recommended Posts

Here's an example

 

<?php
/**
* create a database connection and select a database
*/

$host = 'localhost';
$username = '';
$password = '';
$dbname = 'test';

$conn = mysql_connect ($host, $username, $password) or die(mysql_error());
mysql_select_db ($dbname, $conn) or die(mysql_error());

/**
* create user table
*/

$sql = "CREATE TABLE user (
            username VARCHAR(10) NOT NULL  PRIMARY KEY,
            password VARCHAR(10),
            email VARCHAR(60)
        )";
mysql_query ($sql) or die(mysql_error());

/**
* now add a record
*/

$sql = "INSERT INTO user (username, password, email) VALUES ('Barand', 'secret', '[email protected]')";
mysql_query ($sql) or die(mysql_error());
?>

 

 

For more info:

 

http://dev.mysql.com/doc/refman/4.1/en/index.html

 

http://www.php.net/manual/en/ref.mysql.php

Link to comment
https://forums.phpfreaks.com/topic/42209-creating-tables-help/#findComment-204750
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.