简体   繁体   English

创建SQL表并填充它

[英]Create SQL Table and Populate it

I have a script that creates a SQL table for me as below 我有一个为我创建SQL表的脚本,如下所示

 if ($con = mysql_connect($host, $username, $password)) {
    if (mysql_select_db($db_name)) {
        $sql = "CREATE TABLE ".$ac_system."_credits (id INT NOT NULL   
 AUTO_INCREMENT , PRIMARY KEY (id) , account_nr CHAR(10) , credits CHAR(10))";    
if (mysql_query($sql, $con)) {
            $insertSuccessful = true;
        } else {
            echo $sql;
            print_r($_POST);
            echo "\n" . mysql_error($con);
            echo "mysql err no : " . mysql_errno($con);
        }   

I would like to add another line/s to populate the above table with fixed information 我想添加另一行以固定信息填充上表

ID - 1 Credits - 10 ACCOUNT_NR - 1 ID-1积分-10 ACCOUNT_NR-1

The above data is constant and doesn't need to be changed once the table is created I am not sure how to populate it in conjunction with the creation of the table. 上面的数据是恒定的,创建表后不需要更改。我不确定如何结合创建表来填充它。 I can populate it from a seperate PHP script but need all to be done on one page 我可以用单独的PHP脚本填充它,但需要在一页上完成所有操作

Maybe you should execute another one query just after successful table creation: 成功创建表后,也许应该执行另一个查询:

 //some php code here
    $insertSuccessful = true;
    mysql_query( "INSERT INTO $ac_system ( account_nr, credits ) VALUES ( '1', '10' )", $sql );
// and here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM