Ruth Posted April 23, 2008 Share Posted April 23, 2008 I'm not sure if this is where I'm supposed to post this question but I can connect to the database with command prompt, but i can't connect in my script. Here is my code could someone tell me why I can't seem to connect. @ $db = new mysqli('localhost', '', '', 'client2'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later'; exit; } I've also tired @ $db = new mysqli('localhost', 'user', '', 'client2'); I've used this code before in other projects and it worked there. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/ Share on other sites More sharing options...
Spaceman-Spiff Posted April 23, 2008 Share Posted April 23, 2008 I'm not sure what's inside your mysqli class... but perhaps you can echo mysql_error() to find out the exact error message. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525136 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 echo mysqli_error($db); gave me this Couldn't fetch mysqli Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525144 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 remove the @ it only supresses errors Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525155 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 ok wtf i get Access denied for user 'ODBC'@'localhost' (using password: NO) Why would my access be denied when I can access it through the command prompt and run queries through there? Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525164 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 your syntax is of change <?php $db = new mysqli('localhost', '', '', 'client2'); ?> To: <?php $db = new mysqli("localhost", "username","password");?> Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525246 Share on other sites More sharing options...
IsmAvatar Posted April 23, 2008 Share Posted April 23, 2008 Access is denied because you haven't specified a username and password. If you've set up a fresh mysql install, your username is probably 'root' and password is probably empty ''. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525251 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 Access denied for user 'username'@'localhost' I've tired root and it didn't work either. I was reading on another form that using root leaves a hole for people to get into. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525255 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 try using odbc_connect() instead of new mysqli Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525258 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 Are there any parameters? I've always used mysqli but for some reason it just doesn't want to work now. I don't understand why all of the sudden it doesn't want to work. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525261 Share on other sites More sharing options...
IsmAvatar Posted April 23, 2008 Share Posted April 23, 2008 Yes, using root does leave a hole, simply because the password is blank. But a fresh install of MySql usually sets you up with a root username and a blank password. The problem here, as I've said before, is that you're not connecting with a username or password. You're leaving them blank. a user "username" with a blank password is just as insecure as "root" with a blank password - they both have a blank password. Please make sure your username and password are correct before you attempt connecting with those. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525266 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 odbc_connect ( string $dsn , string $user , string $password [, int $cursor_type ] ) example: <?php $db_host = "server.mynetwork"; $db_user = "dbuser"; $db_pass = "dbpass"; $dsn = "DRIVER={MySQL ODBC 3.51 Driver};" . "CommLinks=tcpip(Host=$db_host);" . "DatabaseName=$db_name;" . "uid=$db_user; pwd=$db_pass"; odbc_connect($dsn, $db_user, $db_pass); ?> Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525267 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 It doesn't like the $dsn or the other vars, it says its unexpected Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525268 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 look at my example above Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525270 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\projects\new_client\WWW\dbconnection.php on line 19 I don't know anything about odbc all I've ever used is mysqli or mysql Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525272 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 my bad you need mysqli_connect() $db=mysqli_connect("localhost","user","password"); Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525278 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'user'@'localhost' (using password: YES) in Same error Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525323 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 did you replace "user" with the actual database username ??? and do you have an actual password or is it blank ??? Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525326 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 I don't know the username I just pulled something out my bum and I have no password. How do I find the db username. When I created the database i just did the usual create database client2; Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525332 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 client2 is the database name. you need to go into PHPMYADMIN and create a user for your table and give it unlimited permissions. thats why you cant connect it has no user for your database. Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525334 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 Come to think of it I never assigned permissions when I created the database does that affect anything? Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525335 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 Ding frys are done I'm still not used to php sql I'll create the permissions thanks Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525336 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 http://www.smartwebby.com/PHP/database_table_create.asp a useful tutorial on tables Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525338 Share on other sites More sharing options...
Ruth Posted April 23, 2008 Author Share Posted April 23, 2008 I got it I just keep forgetting to do the permissions. Thanks for your help Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525342 Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 if it is now connecting please clicked solved thanks Link to comment https://forums.phpfreaks.com/topic/102558-db-connection/#findComment-525343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.