我正在尝试使用 php 在 mysql 中创建一些临时表 [英] Im trying to create some temporary tables in mysql using php

查看:58
本文介绍了我正在尝试使用 php 在 mysql 中创建一些临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 php 在 mysql 中创建一些临时表

我的代码:

但它给出了一个错误您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的 '' 附近使用的正确语法"

我的 MySQL 版本如下

MySQL Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i686) using readline 5.1

我对 php 编码不太流利,请有人帮我吗??

解决方案

我不知道你为什么想要这样的表名,但你需要标识符引号(反引号)才能工作.

<前>`#temp1`

您需要引用,否则它将被视为评论.#

$maketemp = "创建表`#temp1` (`id` INT(11) NOT NULL AUTO_INCREMENT,`date` varchar(50),`csc` varchar(50),`effectedareas` varchar(50),`agent` varchar(50),主键(`id`)) COLLATE = 'utf8_general_ci'";

请不要使用 mysql_* 函数,它们已被弃用.点击此处.

Hi I'm trying to create some temporary tables in mysql using php

my code:

<?php
mysql_connect("localhost","root","sahan");//database connection
mysql_select_db("callcenter");

$maketemp="create table #temp1 (id varchar(50),date varchar(50),csc varchar(50),effectedareas varchar(50),agent varchar(50))";

$data1 = mysql_query($maketemp)
 or die(mysql_error());

?>

but it gives an 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 '' at line 1"

My MySQL version is as below

MySQL Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i686) using readline 5.1

I'm not much fluent in php coding please can some one help me??

解决方案

I do not know why you want a table name like that but you need indentifier quotes (backticks) for it to work.

`#temp1`

You need quotes or else it will considered a comment. #

$maketemp = "CREATE TABLE `#temp1` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `date` varchar(50),
    `csc` varchar(50),
    `effectedareas` varchar(50),
    `agent` varchar(50),
    PRIMARY KEY (`id`)
) COLLATE = 'utf8_general_ci'
";

Please refrain from using mysql_* functions, they are deprecated. Click here.

这篇关于我正在尝试使用 php 在 mysql 中创建一些临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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