# \[php/mysql\] How do you create a database from php?

**URL:** https://forum.kirupa.com/t/php-mysql-how-do-you-create-a-database-from-php/71082
**Category:** programming
**Created:** [November 20, 2004, 7:56pm UTC](https://forum.kirupa.com/t/php-mysql-how-do-you-create-a-database-from-php/71082 "2004-11-20T19:56:30Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![goldy2006](https://avatars.discourse-cdn.com/v4/letter/g/e8c25b/32.png) [@goldy2006](https://forum.kirupa.com/u/goldy2006)
#### Post date: [November 20, 2004, 7:56pm UTC](https://forum.kirupa.com/t/php-mysql-how-do-you-create-a-database-from-php/71082/1 "2004-11-20T19:56:30Z")

</div>

I tried to create a mysql database from php with the following code (with my password and username filled in):

```php

<?php
$connection = mysql_connect('localhost', 'username', 'password');
if (!$connection) 
{
   die('Could not connect: ' . mysql_error());
}

if (mysql_create_db('my_db')) 
{
   echo "Database created successfully
";
} 
else 
{
   echo 'Error creating database: ' . mysql_error() . "
";
}

?> 

```

but I got the following error message:  
**Fatal error:** Call to undefined function: mysql\_create\_db() in **/home/goldy/public\_html/test.php** on line **10**

Can someone tell me what I’m doing wrong? The hosting service I use has both mysql and php installed and working.

Thanks for you help,  
Matt :h:
