Jump to content

[SOLVED] Why wont this script create the whole database etc


Recommended Posts

<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "blog";

$con = mysqli_connect ("$dbhost","$dbuser","$dbpass")
or die ("Could not connect to server");

$sql = "CREATE TABLE 'bloggy'.'$dbname' (
'title' VARCHAR(32) NOT NULL,
'timedate' VARCHAR(32) NOT NULL,
'message' VARCHAR(10000) NOT NULL,
'ID' INT( NOT NULL AUTO_INCREMENT, PRIMARY KEY ('ID'), UNIQUE ('title', 'ID')
) ENGINE = MyISAM

CREATE TABLE '$dbname'.'password' (
'password' VARCHAR( NOT NULL, INDEX ('password')
) ENGINE = MyISAM

INSERT INTO '$dbname'.'password' ('password') VALUES (\'463997\') ";

$query = mysqli_query($con, $sql)
or die ("Could not execute install query." . mysql_error());

?>

 

I just get the "Could not execute install query." error? I copied everything exactly from phpmyadmin!

Try separating each SQL statement with a ;

 

$sql = "CREATE TABLE 'bloggy'.'$dbname' (
'title' VARCHAR(32) NOT NULL,
'timedate' VARCHAR(32) NOT NULL,
'message' VARCHAR(10000) NOT NULL,
'ID' INT( NOT NULL AUTO_INCREMENT, PRIMARY KEY ('ID'), UNIQUE ('title', 'ID')
) ENGINE = MyISAM
;

CREATE TABLE '$dbname'.'password' (
'password' VARCHAR( NOT NULL, INDEX ('password')
) ENGINE = MyISAM
;

INSERT INTO '$dbname'.'password' ('password') VALUES (\'463997\');
";

GRrRrrrRRRrrRRrRRRrRRRRRrrRrrR!

 

This works:

 

<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "blog";

$con = mysqli_connect ("$dbhost","$dbuser","$dbpass")
or die ("Could not connect to server");

$sql = "CREATE TABLE `hello`.`bloggy6` (
`test` VARCHAR(2) NOT NULL,
`id` VARCHAR(2) NOT NULL,
`me` VARCHAR(2) NOT NULL,
`see` VARCHAR(2) NOT NULL)
ENGINE = MyISAM";

$query = mysqli_multi_query($con, $sql)
or die ("Could not execute install query." . mysql_error());

?>

 

This does not

<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "blog";

$con = mysqli_connect ("$dbhost","$dbuser","$dbpass")
or die ("Could not connect to server");

$sql = "CREATE TABLE 'hello'.'bloggy6' (
'test' VARCHAR(2) NOT NULL,
'id' VARCHAR(2) NOT NULL,
'me' VARCHAR(2) NOT NULL,
'see' VARCHAR(2) NOT NULL)
ENGINE = MyISAM";

$query = mysqli_multi_query($con, $sql)
or die ("Could not execute install query." . mysql_error());

?>

 

FFS its the ' or ` story again! I feel like smashing my keyboard  >:(... Why does MYSQL expect ` rather than ' in creating stuff withing databases?...

 

I thought PHP is ment to be a 'allowing and not strict' language!

 

Btw how exactly does the 'php mailing lists' work? I thought it works like a bullitin board but I read that I am gonna get 200 emails a day... Uhm that wont be cool :-(

FFS its the ' or ` story again! I feel like smashing my keyboard  >:(... Why does MYSQL expect ` rather than ' in creating stuff withing databases?...

 

I thought PHP is ment to be a 'allowing and not strict' language!

Don't confuse PHP and MySQL, or treat them as "one and the same". They are totally different creatures, written by totally different people to do totally different things. The fact that MySQL expects a particular syntax has nothing at all to do with PHP.

Oh i see what your saying... I thought mysql is just a spreadsheet thing and PHP 'does the work' while mysql just stores it... that gives me a question.. Would you be able to use mysql with C++?  Lastly i will try dropping the ' but uhm what exactly is 'reversed words'? 'sdrow desrever'

Would you be able to use mysql with C++?
PHP has a special library (sometimes known as a driver) that allows it to interact with MySQL. This is a custome written extension (normally included in any standard build of PHP, although it's no longer the default to include it automatically when building PHP) Similar drivers exist for PHP to interact with other databases such as Microsoft SQL Server, Oracle, Postgres, etc. None of these databases are part of PHP, but somebody somewhere has written a driver module/library that allows the two progams (PHP and the database) to work together.

 

Similarly, languages like Perl also have drivers that permit them to interact with databases like MySQL, Oracle, Postgres, etc. I don't know if there is a MySQL driver for C++, but I would imagine so (depending on your flavour of C++).

 

 

Would you be able to use mysql with C++?  Lastly i will try dropping the ' but uhm what exactly is 'reversed words'?

MySQL uses a special programming langauge called SQL to read and write data, based on the standard SQL language that is common across almost all relational databases (MS SQL Server, Oracle, Postgres, Sybase, etc). Words like SELECT, INSERT, UPDATE and DELETE are 'reserved' words, because they are the basic commands of SQL; similarly CREATE, DATABASE, VARCHAR, INTEGER, TIMESTAMP, etc. because they are all a part of the SQL language.

If you want to create a table or a column that shares its name withy one of these reserved words, then SQL needs to know that (for example) CREATE is the name of your table, not an instruction to try creating a new database or table. It's not generally considered good practise to give tables or columns the same name as one of these SQL language reserved words, but using the backticks around the name allows SQL to understand that CREATE is a keyword and `CREATE` is a table or column name

they're reserved not reversed

These are words that have special meaning for MySQL and should not be used as names for database objects. Full list is in manual here:

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

 

Yes, you can use MySQL with C++, as well as other languages. See connectors available from MySQL developers for some examples

http://dev.mysql.com/downloads/connector/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.