I need to create a table in my existing DB & did some googling but don't get to understand how exactly will I be able to create this table. Here is the table I need to create in my existing DB CREATE TABLE IF NOT EXISTS `uc_affiliate_product_commission` ( `nid` mediumint(9) NOT NULL, `commission_structure` longtext NOT NULL, PRIMARY KEY (`nid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; PHP: I found one of the tutorial which explains how to create the DB table but can't figure out where to put what to generate table as required, here is what I got, plz explain where I put what values from the above so it generates the table. <?php // set your infomation. $dbhost='localhost'; $dbusername='david'; $dbuserpass='mypassword'; $dbname='test'; // connect to the mysql database server. $link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass); echo "success in database connection."; // select the specific database name we want to access. $dbname=$dbusername."_".$dbname; if (!mysql_select_db($dbname)) die(mysql_error()); echo "success in database selection."; // add a table to the selected database $result="CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))"; if (mysql_query($result)){ echo "success in table creation."; } else { echo "no table created."; } ?> PHP:
<?php // set your infomation. $dbhost='localhost'; $dbusername='david'; $dbuserpass='mypassword'; $dbname='test'; // connect to the mysql database server. $link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass); echo "success in database connection."; // select the specific database name we want to access. $dbname=$dbusername."_".$dbname; if (!mysql_select_db($dbname)) die(mysql_error()); echo "success in database selection."; // add a table to the selected database $result="CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))"; if (mysql_query($result)){ echo "address_book - success in table creation."; } else { echo "address_book - no table created."; } $result2="CREATE TABLE IF NOT EXISTS uc_affiliate_product_commission (nid mediumint(9) NOT NULL, commission_structure longtext NOT NULL, PRIMARY KEY (nid))"; if (mysql_query($result2)){ echo "uc_affiliate_product_commission - success in table creation."; } else { echo "uc_affiliate_product_commission - no table created."; } ?> PHP: Now I cannot say it will work or not i haven't tested it on my end. I didn't even test the SQL statement you wanted to be added. But that Logic should work. Also little note: The first table being created is not checking to see if it exist which is not good. depending on your setup correct me if i am wrong can overwrite the table that is already created which may cost data lost. The 2nd query checks then create the table that is needed, which is good. Good luck. hope it helps.
<?php // set your infomation. $dbhost='localhost'; $dbusername='david'; $dbuserpass='mypassword'; $dbname='test'; // connect to the mysql database server. $link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass); echo "success in database connection."; // select the specific database name we want to access. $dbname=$dbusername."_".$dbname; if (!mysql_select_db($dbname)) die(mysql_error()); echo "success in database selection."; $result1="CREATE TABLE IF NOT EXISTS uc_affiliate_product_commission (nid mediumint(9) NOT NULL, commission_structure longtext NOT NULL, PRIMARY KEY (nid))"; if (mysql_query($result1)){ echo "uc_affiliate_product_commission - success in table creation."; } else { echo "uc_affiliate_product_commission - no table created."; } ?> PHP: that will do it. remember if you're specifying default values and need to use quotes, use a backslash as an escape character. BTW: this script just runs whatever SQL is in "$result1", but it runs it in the ifstatement which works, but i don't like being a java programmer. Legal, but crazy. think its standard in PHP though. hope this helps.
<?php // set your infomation. $dbhost='localhost'; $dbusername='david'; $dbuserpass='mypassword'; $dbname='test'; // connect to the mysql database server. $link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass); echo "success in database connection."; // select the specific database name we want to access. $dbname=$dbusername."_".$dbname; if (!mysql_select_db($dbname)) die(mysql_error()); echo "success in database selection."; $result1="CREATE TABLE IF NOT EXISTS uc_affiliate_product_commission (`nid` mediumint(9) NOT NULL, `commission_structure` longtext NOT NULL, PRIMARY KEY (`nid`))"; if (mysql_query($result1)){ echo "uc_affiliate_product_commission - success in table creation."; } else { echo "uc_affiliate_product_commission - no table created."; } ?> PHP: instead use rambo script you also may use mine... the diff only ` sign