创建一个包含电子邮件地址作为标题的SQL表 [英] Creating an SQL table with email address as title

查看:165
本文介绍了创建一个包含电子邮件地址作为标题的SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用的代码会产生以下错误:


您的SQL语法有错误;检查手册,
对应于您的MySQL服务器版本的正确语法使用
附近'@ gmail.com(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),
name VARCHAR'在第1行


以及相关的代码是:

  //为用户创建新表
//创建一个MySQL连接
mysql_connect(localhost,$ sqlusername,$ sqlpassword)或死(mysql_error() );
mysql_select_db($ db_name)或die(mysql_error());

//在所选数据库中创建一个MySQL表$ b $ mysql_query(CREATE TABLE $ emailaddress (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
age INT))
或者死(mysql_error() );

当我从变量 $输入一个值时, emailaddress 不是电子邮件地址,即没有 @ 符号如果它包含一个 @ 符号,则会显示该错误。

解决方案

你应该能够通过用反引号(`)转义表名来解决这个问题。但实际上对于大多数情况来说,这是设计数据库的不好的方法。



您应该使用一个带有emailaddress字段的表,而不是为每个用户/电子邮件创建一个新表地址,除非您有特定的需要。


I'm struggling to create SQL tables using email addresses as the table name.

The code I am using produces the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR' at line 1

and the related code is:

// create new table for users tosses
    // Make a MySQL Connection
        mysql_connect("localhost", "$sqlusername", "$sqlpassword") or die(mysql_error());
        mysql_select_db("$db_name") or die(mysql_error());

// Create a MySQL table in the selected database
        mysql_query("CREATE TABLE $emailaddress(
        id INT NOT NULL AUTO_INCREMENT, 
        PRIMARY KEY(id),
        name VARCHAR(30), 
        age INT)")
        or die(mysql_error());  

It works just fine when I input a value from the variable $emailaddress that is not an email address i.e. doesnt have an @ symbol, but it shows that error if it includes an @ symbol.

解决方案

You should be able to get around this by escaping the table name with backticks (`). But really for most circumstances this is a bad way to design your database.

You should use one table with an emailaddress field instead of creating a new table for each user/email address, unless you have a specific need to do so.

这篇关于创建一个包含电子邮件地址作为标题的SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆