cs.punk Posted February 27, 2009 Share Posted February 27, 2009 <?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! Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/ Share on other sites More sharing options...
Mark Baker Posted February 27, 2009 Share Posted February 27, 2009 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\'); "; Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772435 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 mysqli_query can only execute one query at a time. Use mysqli_multi_query instead. Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772449 Share on other sites More sharing options...
cs.punk Posted February 27, 2009 Author Share Posted February 27, 2009 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 :-( Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772600 Share on other sites More sharing options...
Mark Baker Posted February 27, 2009 Share Posted February 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772618 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 And I tell you what. You can drop ` completely as long as you don't use reserved words as names for your database objects. Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772667 Share on other sites More sharing options...
cs.punk Posted February 27, 2009 Author Share Posted February 27, 2009 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' Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772699 Share on other sites More sharing options...
Mark Baker Posted February 27, 2009 Share Posted February 27, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772716 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 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/ Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772719 Share on other sites More sharing options...
cs.punk Posted February 27, 2009 Author Share Posted February 27, 2009 I so so so put my hat down for you guys! Thanks so much! and lol @ the reversed. A big thank you Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772879 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 I so so so put my hat down for you guys! Thanks so much! and lol @ the reversed. A big thank you You're welcome! And I chuckled a lot at 'sdrow desrever' Quote Link to comment https://forums.phpfreaks.com/topic/147129-solved-why-wont-this-script-create-the-whole-database-etc/#findComment-772887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.