nomadrw Posted November 21, 2009 Share Posted November 21, 2009 Hello everyone. I'm having troubles creating a db with a query. I'm reading a book called PHP Bibles from Tim Converse I get this error Fatal error: Call to undefined function mysql_create_db() in /Applications/XAMPP/xamppfiles/htdocs/testing/10/ch22/weblog_db_create.php on line 8 Not sure why and help would be great. Here is the code: <?php // You'll probably have to be the root MySQL user to run this script. // If you can't get that permission, you could alter the script below // to create tables in your pre-existing database. include("db_password.inc"); mysql_connect($hostname, $user, $password) or die("Failure to communicate"); $try_create = mysql_create_db("weblogs"); if ($try_create > 0) { echo ("Successfully created database.<BR>\n"); mysql_select_db("weblogs"); $query = "CREATE TABLE login (ID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(20), password VARCHAR(20))"; $result = mysql_query($query); // Since we're not using the standard MySQL // date format, store date as an integer $query2 = "CREATE TABLE mylog (ID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, date INT(, blogtext TEXT)"; $result2 = mysql_query($query2); mysql_close(); if ($result > 0 && $result2 > 0) { echo ("Successfully created tables<BR>\n"); } else { echo ("Unable to create tables."); } } else { echo ("Unable to create database"); } ?> Password for db_password.inc localhost nomad nomad Many thanks Damon Quote Link to comment https://forums.phpfreaks.com/topic/182352-creating-a-db-with-a-query/ Share on other sites More sharing options...
nomadrw Posted November 21, 2009 Author Share Posted November 21, 2009 opps line 8 is this $try_create = mysql_create_db("weblogs"); Also I'm using PHP 5.3.0 On a Mac using XAMPP 1.7.2a If you need any more info please let me know Thanks Quote Link to comment https://forums.phpfreaks.com/topic/182352-creating-a-db-with-a-query/#findComment-962321 Share on other sites More sharing options...
Brandon_R Posted November 21, 2009 Share Posted November 21, 2009 The function mysql_create_db will not be available if the mysql extension was built against a MySQL 4.x client library. This function is also depreciated. Use a mysql_query to create a DB instead. Quote Link to comment https://forums.phpfreaks.com/topic/182352-creating-a-db-with-a-query/#findComment-962331 Share on other sites More sharing options...
nomadrw Posted November 21, 2009 Author Share Posted November 21, 2009 Use a mysql_query to create a DB instead. I do this inside the phpmyadmin? If so How do i create the tables with the query. that I have listed above or should I just create the SQL inside phpmyadmin. thanks damon Quote Link to comment https://forums.phpfreaks.com/topic/182352-creating-a-db-with-a-query/#findComment-962341 Share on other sites More sharing options...
mikesta707 Posted November 21, 2009 Share Posted November 21, 2009 You can create a database with a sql query, as brandon said, and simply use mysql_query(). check out this for the syntax Quote Link to comment https://forums.phpfreaks.com/topic/182352-creating-a-db-with-a-query/#findComment-962391 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.