我试图在我成功创建的SQL数据库中创建一个表。但是,我似乎无法让它发挥作用。
我基本上按照w3的分步指南进行操作,但它仍然无效。
任何人都能看到我失踪的东西吗?
#include<stdio.h>
#define m 100
#define n 60
int main(void) {
char file_name[m]; FILE *input_file;
int symb, symbcount[10]={0};
int i;
printf("Enter name of the input file: "); scanf("%s", file_name);
input_file = fopen(file_name, "r");
while (input_file == NULL) {
printf("Error: There is no file \"%s\"\n", file_name);
printf("Enter file name (or \".\" to exit): "); scanf("%s", file_name);
if (strcmp(file_name, ".") == 0) return 1;
input_file = fopen(file_name, "r");
}
while ((symb=getc(input_file))!=EOF){
if (symb >= '0' && symb <='9')
symbcount[symb-'0']++;
}
fclose(input_file);
for (i=0; i<10; i++)
printf("%d: %d\n", i, symbcount[i]);
return 0;
}
&GT;
答案 0 :(得分:1)
首先,您需要在代码所在的数据库中创建任何表之前选择数据库。
$conn->select_db ( "enigmaPaamelding");
之后你必须在sql查询中运行你的最后一个$ sql变量。
// Create table
if ($conn->query($sql) === TRUE) {
echo "table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
最终代码在这里:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);
// Create database
$sql = "CREATE DATABASE enigmaPaamelding";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->select_db ( "enigmaPaamelding");
// sql to create table
$sql = "CREATE TABLE BedriftPaameldinger (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(30) NOT NULL,
name VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
// Create table
if ($conn->query($sql) === TRUE) {
echo "table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
答案 1 :(得分:0)
您必须在creatinng表之前选择数据库:call
$conn->select_db ( "enigmaPaamelding");
创建数据库后。