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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 remove the @ it only supresses errors Quote Link to comment 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? Quote Link to comment 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");?> Quote Link to comment 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 ''. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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); ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 23, 2008 Share Posted April 23, 2008 look at my example above Quote Link to comment 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 Quote Link to comment 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"); Quote Link to comment 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 Quote Link to comment 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 ??? Quote Link to comment 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; Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.