Jump to content

db connection


Ruth

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.