Re: How to create a table from PHP?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: How to create a table from PHP?

From: Jerry Stuckle <jstucklex@attglobal.net>
Date: Mon Jul 18 2005 - 03:15:36 CEST

mh wrote:
> Hello,
>
> Andy Hassall a écrit :
>
>>On 17 Jul 2005 09:42:34 -0700, "mh" <marchenri1@gmail.com> wrote:
>>
>>
>>>$sql_query="CREATE TABLE '$num' (
>>
>> Don't put quotes around identifier names. If you must, then in MySQL use
>>either ` or ", but not '. ' is for strings, not identifiers.
>
> Ok, but I did that I think. I said in my message that I also tried like
> that:
> $sql_query = 'CREATE TABLE $num ('
> . ' `variable1` DATE NOT NULL'
> . ' )';
> In this case I don't use the quotes around the name of the table but
> MySQL still creates a table called $num and doesn't replace the
> variable $num but its value like I wish.
>
> I also tried:
> $sql_query="CREATE TABLE $num (variable DATE NOT NULL)";
> but without success.
> I feel that I tried every possible combiantion without success. There
> must be a solution. But what is it?
>

Look at strings in the PHP manual.

When enclosed in single quotes, variable substitution does NOT take place - so
your table name becomes $num.

When you enclose a string in double quotes, PHP will substitute variables. So
you should have something like:

$sql_query = "CREATE TABLE $num ("
              ^ ^

Note double quotes instead of single quotes. See
http://www.php.net/manual/en/language.variables.php.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Received on Mon Oct 17 21:09:35 2005