0

The application is only able to connect with a manually developed database in phpmyadmin but not able to create a database from the php.

here is the code (install_database.php) for creating that database

<?php
$cn = mysql_connect('localhost','root','') or
        die('Unable to connect. Check connection parameters.');

$sql = 'CREATE DATABASE IF NOT EXISTS cars';

mysql_query($sql, $cn) or 
        die(mysql_error($cn));

mysql_select_db('cars') or
        die(mysql_error($cn));

$sql = 'CREATE TABLE IF NOT EXISTS user (
            user_id             INTEGER UNSIGNED        NOT NULL AUTO_INCREMENT,
            user_username       VARCHAR(80)             NOT NULL,
            user_password       VARCHAR(80)             NOT NULL,
            user_join_date      INTEGER UNSIGNED        NOT NULL,
            user_age            INTEGER UNSIGNED        NOT NULL,
            user_country        VARCHAR(100)            NOT NULL,

            PRIMARY KEY (user_id)
            )
            ENGINE=MyISAM';

mysql_query($sql,$cn) or 
        die(mysql_error($cn));



?>

its showing unknown database 'cars' on the browser. if any additional detail is required please inform.

2
  • 1
    possible duplicate of Php mysql create database if not exists Commented Apr 15, 2014 at 15:46
  • Still can't figure out the reason for not creating the database. How can I verify why is not creating the database? Commented Apr 15, 2014 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.