thehigherentity Posted June 12, 2006 Share Posted June 12, 2006 im trying to get better with mysql and at the moment im trying to create a new database with php code, however it just wont work i have looked all over and read just about everything i can find about creating a dbaccording to the admin section of my server i Im usingPHP version 5.0.5 andMySQL version 4.1.19and i have the rights to create and drop databases as well as change the tables etcI first tried myaql_create_db befor i found out this will not workI believe the right code is ment to be mysql_query("CREATE DATABASE my_db")however this wont work eather, all i get is an error saying somthing likeAccess denied for user 'username'@'localhost' to database 'my_db'but i can connect and read the other already existing databases?is there somthing im missing here i was under the impresion mysql was easy to connect tois there anyway i can test my privaliges and see if its somthing like that? or any other ideas would be great Quote Link to comment https://forums.phpfreaks.com/topic/11765-create-database-mysql-just-wont-work/ Share on other sites More sharing options...
Barand Posted June 12, 2006 Share Posted June 12, 2006 try[code]$cnx = mysql_connect('localhost', '*****', '*******');mysql_select_db('mysql');$sql = "SELECT * FROM user WHERE user = 'myusername'";$res = mysql_query($sql);$row = mysql_fetch_assoc($res);echo '<pre>', print_r($row, true), '</pre>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11765-create-database-mysql-just-wont-work/#findComment-44557 Share on other sites More sharing options...
d_barszczak Posted June 12, 2006 Share Posted June 12, 2006 [!--quoteo(post=382764:date=Jun 12 2006, 07:18 AM:name=thehigherentity)--][div class=\'quotetop\']QUOTE(thehigherentity @ Jun 12 2006, 07:18 AM) [snapback]382764[/snapback][/div][div class=\'quotemain\'][!--quotec--]according to the admin section of my server i Im usingPHP version 5.0.5 andMySQL version 4.1.19[/quote]Guessing by the above you are using a hosting company as apposed to running your own local web server.If this is the case a lot of hosting companies (Including Mine) will allow you to create your own Databases but only through their admin interface. I have a test server which i use and the following code worked for me on that server but not on my ISP Server.[code]<?php $query = "CREATE DATABASE my_db";$user = "username";$pass = "password";$host = "localhost";mysql_connect($host, $user, $pass) or die(mysql_error());mysql_query($query) or die(mysql_error());?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11765-create-database-mysql-just-wont-work/#findComment-44558 Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 Chances are, your webhosting company doesn't let you to access the "mysql" database, let alone modify it. Quote Link to comment https://forums.phpfreaks.com/topic/11765-create-database-mysql-just-wont-work/#findComment-44596 Share on other sites More sharing options...
thehigherentity Posted June 12, 2006 Author Share Posted June 12, 2006 [!--quoteo(post=382793:date=Jun 12 2006, 06:03 AM:name=scripts2go.co.uk)--][div class=\'quotetop\']QUOTE(scripts2go.co.uk @ Jun 12 2006, 06:03 AM) [snapback]382793[/snapback][/div][div class=\'quotemain\'][!--quotec--]Guessing by the above you are using a hosting company as apposed to running your own local web server.If this is the case a lot of hosting companies (Including Mine) will allow you to create your own Databases but only through their admin interface. I have a test server which i use and the following code worked for me on that server but not on my ISP Server.[code]<?php $query = "CREATE DATABASE my_db";$user = "username";$pass = "password";$host = "localhost";mysql_connect($host, $user, $pass) or die(mysql_error());mysql_query($query) or die(mysql_error());?>[/code][/quote]I think you could be right, I have created a db through the admin area and I have managed to create the tables etc with code so it seems its the server host company thats blocking my code from making the db.but never mind, now i just have to get my head round getting the data into the database lolIm sure i will be posting again soon!thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/11765-create-database-mysql-just-wont-work/#findComment-44779 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.